codeforces 922 C Cave Painting

Description

Imp is watching a documentary about cave painting.

Imp

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
  • nmodi=nmodj , where xmody is the remainder of division x by y .

Input

The only line contains two integers n, k (1 ≤ n, k ≤ 10 18 ).

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 mod 1~k每个数的余数是不是都不相同
思路:稍微用一下数学归纳法的思想,假设每个余数都不相同,因为 nmod1=0 ,所以 nmod2=1 (因为任何数对2取模只能取0或1,而0已经被占用了),同理 nmod3=2 ,..., nmodk=k1 。是不是很神奇? k 可以取到10 18 ,而要同时满足这么多条件的数,应该是不存在的或者超级大吧。

我不知道怎么严格地证明我的猜想,只能简单推理一下:满足 nmod2=1 的数有 1, 3, 5, 7, 9, … 在此基础上满足 nmod3=2 的数,就只有 5, 11, 17, …了,容易发现剩下的数仍然是等差数列,但公差扩大了3倍。同样的,在此基础上,再满足 nmod4=3 的数就只有 11, 23, 35, …了。我觉得公差增长的这个速度都接近阶乘了,而且首项增长的也是飞快,所以要让 n 1k 取模的每个余数都满足条件,那 n 差不多至少应该是 k! 级别的。反过来说,即使是10 18 ,它能满足的k也不可能很大(大概在20个左右)。

总结一下就是,题目给的条件是一个很强的条件,只需要检查 n 对从1开始很少几个数取模的结果,就能确定 n 是不是符合要求的了。数学功底不是很扎实,有很多地方不够严谨,不要在意细节~

#include 
long long n, k;

int main() {
    scanf("%I64d %I64d", &n, &k);
    bool flag = true;
    for (long long i = 1; i <= k&&flag; ++i) {
        if (n%i != i - 1)flag = false;
    }
    if (flag)printf("Yes");
    else printf("No");
}

你可能感兴趣的:(acm)