zoukankan      html  css  js  c++  java
  • Codeforces Round #411 A. Fake NP

    A. Fake NP
    time limit per test  
    1 second
    memory limit per test  
    256 megabytes
     

    Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.

    You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.

    Solve the problem to show that it's not a NP problem.

    Input

    The first line contains two integers l and r (2 ≤ l ≤ r ≤ 109).

    Output

    Print single integer, the integer that appears maximum number of times in the divisors.

    If there are multiple answers, print any of them.

     
    input
    19 29
    output
    2
    input
    3 6
    output
    3
    Note:

    The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.

    The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.

    题目大意:

         给定一个范围,输出一个整数x,(使得这个范围内能整除x的整数个数最多)

    解题思路:

         刚开始写的时候没想辣么多,处理超级复杂,之后仔细想想其实只有两种情况

         1、当l和r相同时任意输出一个。  2、当l和r不同时输出2(所有的偶数都能被2整除)

    AC代码:

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <math.h>
     4 #include <stdlib.h>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 int main ()
     9 {
    10     int l,r;
    11     while (~scanf("%d %d",&l,&r))
    12     {
    13         if (l == r)
    14             printf("%d
    ",l);
    15         else
    16             printf("2
    ");
    17     }
    18     return 0;
    19 }
  • 相关阅读:
    康复计划
    Leetcode 08.02 迷路的机器人 缓存加回溯
    Leetcode 38 外观数列
    Leetcode 801 使序列递增的最小交换次数
    Leetcode 1143 最长公共子序列
    Leetcode 11 盛水最多的容器 贪心算法
    Leetcode 1186 删除一次得到子数组最大和
    Leetcode 300 最长上升子序列
    Leetcode95 不同的二叉搜索树II 精致的分治
    Leetcode 1367 二叉树中的列表 DFS
  • 原文地址:https://www.cnblogs.com/yoke/p/6860918.html
Copyright © 2011-2022 走看看