CodeForces 687B Remainders Game(反证法转化题意)

题目链接https://vjudge.net/contest/373416#problem/G
Today Pari and Arya are playing a game called Remainders.

Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value . There are n ancient numbers c 1, c 2, …, c n and Pari has to tell Arya if Arya wants. Given k and the ancient values, tell us if Arya has a winning strategy independent of value of x or not. Formally, is it true that Arya can understand the value for any positive integer x?

Note, that means the remainder of x after dividing it by y.

Input
The first line of the input contains two integers n and k (1 ≤ n,  k ≤ 1 000 000) — the number of ancient integers and value k that is chosen by Pari.

The second line contains n integers c 1, c 2, …, c n (1 ≤ c i ≤ 1 000 000).

Output
Print “Yes” (without quotes) if Arya has a winning strategy independent of value of x, or “No” (without quotes) otherwise.
Input

4 5
2 3 5 12

Output

Yes

Input

2 7
2 3

Output

No

翻译
输入n和k,第二行有n个数 c i c_i ci,有一个未知数x,知道x% c i c_i ci的值。问x%k是否有唯一解?

反证法
假设解不唯一,有两个解 x 1 x_1 x1 x 2 x_2 x2,那么 x 1 x_1 x1 x 2 x_2 x2满足:

x 1 x_1 x1% c i c_i ci= x 2 x_2 x2% c i c_i ci x 1 x_1 x1%k!= x 2 x_2 x2%k
由上述式子可以得出:
x 1 x_1 x1- x 2 x_2 x2)% c i c_i ci=0,( x 1 x_1 x1- x 2 x_2 x2)% k k k!=0

x 1 x_1 x1- x 2 x_2 x2)为 c i c_i ci的若干倍, c i c_i ci的若干倍不能整除k

易得
lcm( c 1 c_1 c1, c 2 c_2 c2, c n c_n cn) % c i c_i ci = 0

lcm为 c i c_i ci的若干倍
所以lcm % k != 0

得到命题: 如果解不唯一,那么lcm % k != 0

逆否命题为: 若lcm % k == 0 那么 解唯一

只需要判断lcm是否k 的整数倍
是的话就是yes,否则就是no

代码

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
LL gcd(LL x,LL y)
{
    if(y==0)
        return x;
    return gcd(y,x%y);
}
LL lcm(LL x,LL y)
{
    return x*y/gcd(x,y);
}
int main()
{
    LL n,k,ans=1;
    scanf("%lld%lld",&n,&k);
    if(n==1)
    {
        LL p;
        scanf("%lld",&p);
        if(p%k==0)
            printf("Yes\n");
        else
            printf("No\n");
        return 0;
    }
    while(n--)
    {
        LL p;
        scanf("%lld",&p);
        ans=lcm(p,ans);
        ans%=k;
    }
    if(ans==0)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}

后来遇见她

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zaiyang遇见

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值