zoukankan      html  css  js  c++  java
  • Fake NP CodeForces

    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.

    Examples

    Input
    19 29
    Output
    2
    Input
    3 6
    Output
    3

    Note

    Definition of a divisor: https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html

    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}.

    思路:分两种情况,

    1、R-L<=1 的输出L或者R其中的任意一个。

    2、R-L>=2 那么这个区间里 能被2整除的数一定是最多的数中之一个,因为相邻的两个数必然有一个是偶数,那么偶数就可以被2整除。

    我的AC代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <queue>
    #include <stack>
    #include <map>
    #include <set>
    #include <vector>
    #define rep(i,x,n) for(int i=x;i<n;i++)
    #define repd(i,x,n) for(int i=x;i<=n;i++)
    #define pii pair<int,int>
    #define pll pair<long long ,long long>
    #define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
    #define MS0(X) memset((X), 0, sizeof((X)))
    #define MSC0(X) memset((X), '', sizeof((X)))
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define gg(x) getInt(&x)
    using namespace std;
    typedef long long ll;
    inline void getInt(int* p);
    const int maxn=1000010;
    const int inf=0x3f3f3f3f;
    /*** TEMPLATE CODE * * STARTS HERE ***/
    
    int main()
    {
        ll l,r;
        cin>>l>>r;
        if(l==r)
        {
            cout<<l<<endl;
        }else
        {
            if(r-l>=2)
            {
                cout<<2<<endl;
            }else
            {
                cout<<l<<endl;
            }
        }
        return 0;
    }
    
    inline void getInt(int* p) {
        char ch;
        do {
            ch = getchar();
        } while (ch == ' ' || ch == '
    ');
        if (ch == '-') {
            *p = -(getchar() - '0');
            while ((ch = getchar()) >= '0' && ch <= '9') {
                *p = *p * 10 - ch + '0';
            }
        }
        else {
            *p = ch - '0';
            while ((ch = getchar()) >= '0' && ch <= '9') {
                *p = *p * 10 + ch - '0';
            }
        }
    }

    本博客为本人原创,如需转载,请必须声明博客的源地址。 本人博客地址为:www.cnblogs.com/qieqiemin/ 希望所写的文章对您有帮助。
  • 相关阅读:
    Clean Code读书笔记
    Junit 断言 assertThat Hamcrest匹配器
    SpringMVC 常用注解
    SpringMVC 流程 配置 接口
    ng-select ng-options ng-repeat的用法与区别
    javascript总结
    intellij安装 配置 创建项目
    git常用操作指令
    springmvc报错 org.springframework.web.servlet.DispatcherServlet
    linux笔记:RPM软件包管理-源码包管理
  • 原文地址:https://www.cnblogs.com/qieqiemin/p/10246772.html
Copyright © 2011-2022 走看看