cf #div2.461-C.Cave Painting

C. Cave Painting
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Imp is watching a documentary about cave painting.

Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number n by all integers i from 1 to k. Unfortunately, there are too many integers to analyze for Imp.

Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all 1 ≤ i ≤ k, are distinct, i. e. there is no such pair (i, j) that:

  • 1 ≤ i < j ≤ k,
  • , where  is the remainder of division x by y.
Input

The only line contains two integers nk (1 ≤ n, k ≤ 1018).

Output

Print "Yes", if all the remainders are distinct, and "No" otherwise.

You can print each letter in arbitrary case (lower or upper).

Examples
input
4 4
output
No
input
5 3
output
Yes
Note

In the first sample remainders modulo 1 and 4 coincide.

题意:

给你一个n,k,让你判断n对1到k的所有数字取余结果是否有相同的,若没有则输出Yes,否则输出NO

思路分析:

刚开始写这道题,因为听说队友很简单就过了= =所以以为有很巧妙的方法...想了好久觉得又想不到什么好的方法,后来听队友说两层循环暴力过的,我又觉得这样行不通...又仔细想了想,觉得从n对i取余的情况只有i-1种就是从0到i-1,因为n%1==0 要保证每一个余数都不相同的话,n%2就只能=1那么n%3就只能等于2,所以就是判断n%i是否等于i-1即可


代码:

#include<stdio.h>
long long n,k;
int main()
{

    while(~scanf("%I64d %I64d",&n,&k))
    {
        long long i;
        for(i=1;i<=k;i++)
        {
            if(n%i!=i-1)
            {
                printf("No\n");
                break;
            }
        }
        if(i==k+1)
            printf("Yes\n");
    }





    return 0;
}


猜你喜欢

转载自blog.csdn.net/acm513828825/article/details/79304284
今日推荐