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 … ANOutput 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;
}

本文介绍了一个基于更相减损术原理的算法问题解决方案,通过寻找一组整数的最大公约数来判断是否能通过特定操作得到目标数值。
190

被折叠的 条评论
为什么被折叠?



