AtCoder Grand Contest 018

5 篇文章 0 订阅
3 篇文章 0 订阅

A - Getting Difference

Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement There is a box containing N balls. The i-th ball has
the integer Ai written on it. Snuke can perform the following
operation any number of times:

Take out two balls from the box. Then, return them to the box along
with a new ball, on which the absolute difference of the integers
written on the two balls is written. Determine whether it is possible
for Snuke to reach the state where the box contains a ball on which
the integer K is written.

Constraints 1≤N≤105 1≤Ai≤109 1≤K≤109
All input values are integers.
Input Input is given from Standard Input in the following format:

N K
A1 A2 … AN

Output If it is possible for Snuke to reach the state where the box
contains a ball on which the integer K is written, print POSSIBLE; if
it is not possible, print IMPOSSIBLE.


原地址戳

题解

就是一个更相减损术,hxm大佬%%%%%
找这些数的最大公约数
k%公约数为零就行

#include<algorithm>
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;
int n,k,ans,x;
bool pan;
int pan2;
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        ans=__gcd(x,ans);
        if(k%ans==0)pan=1;
        pan2=max(pan2,x);
    }
    if(pan==1&&pan2>=k)
    cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值