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.
The only line contains two integers n, k (1 ≤ n, k ≤ 1018).
Print "Yes", if all the remainders are distinct, and "No" otherwise.
You can print each letter in arbitrary case (lower or upper).
4 4
No
5 3
Yes
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;
}