Imp is watching a documentary about cave painting.
![](https://i-blog.csdnimg.cn/blog_migrate/b77f28d565ac5363d8b9668de15d6e1c.png)
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%i (1<=i<=k) 的结果是否都互不相等,如果是则输出Yes,否则输出No。
思路;
当i=1时 n%1=0
当i=2时 n%2 为0或者1,但是0 被i=1,时占用,则 n%2只能为1;
当i=3时 n%3=2
当i=4时 n%4=3
当i=5时 n%5=4
。。。。。
当i=k时 n%k=k-1
所有判断当前n%i的结果是否等于i-1,若不等则直接输出No
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;
typedef long long ll;
int main(){
ll n,k;
scanf("%lld%lld",&n,&k);
int flag=1;
for(ll i=1;i<=k;i++)
if(n%i!=i-1){
flag=0;
break;
}
if(flag) printf("Yes\n");
else printf("No\n");
return 0;
}