Codeforces Round#461(Div. 2)(922C)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%i (1<=i<=k) 的结果是否都互不相等,如果是则输出Yes,否则输出No。

第一个例子:

4%1==0

4%2==0

4%3==1

4%4==0

故输出No

第二个例子:

5%1==0

5%2==1

5%3==2

故输出Yes


解题思路:

从i等于1时入手。任何n%1都等于0

i==2时  n%2结果要么为0要么为1 0已经被占用 所以n%2只能等于1

i==3 n%3==2

i==4 n%4==3

:    :

:    :

:    :

i==k n%k==k-1


所有判断当前n%i的结果是否等于i-1,若不等则直接输出no


那么n与k有什么关系呢?

通过k我们能否求出最小的n是多少?


n==lcm(1...k)-1


即是(1到k之间所有的数的最小公倍数)-1


因为lcm+1对所有i (1<=i<=k)都能整除 即 (lcm+1)%i==0

那么(lcm-1)%i==i-1

如:lcm(1...4)==12  

12%1==0(可以看作余数为1) 11%1==0(1-1==0)

12%2==0(可以看作余数为2)  11%2==1(2-1==1)

12%3==0(可以看作余数为3)  11%3==2(3-1==2)

12%4==0(可以看作余数为4)  11%4==3(4-1==3)

 可以看作余数为x的意思是i是x的整数倍 n能被i整除 结果为0


所以对于题目数据中的n,k最大不会超过50


#include<stdio.h>

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






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值