您的位置:首页 > 产品设计 > UI/UE

1562 Guess the number

2016-03-12 21:57 225 查看
[align=left]Problem Description[/align]
Happy new year to everybody!
Now, I want you to guess a minimum number x betwwn 1000 and 9999 to let
(1) x % a = 0;
(2) (x+1) % b = 0;
(3) (x+2) % c = 0;
and a, b, c are integers between 1 and 100.
Given a,b,c, tell me what is the number of x ?

[align=left]Input[/align]
The number of test cases c is in the first line of input, then c test cases followed.every test contains three integers a, b, c.

[align=left]Output[/align]
For each test case your program should output one line with the minimal number x, you should remember that x is between 1000 and 9999. If there is no answer for x, output "Impossible".

[align=left]Sample Input[/align]

2

44 38 49

25 56 3

[align=left]Sample Output[/align]

Impossible

2575

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main()
{
int a,b,c,n,k,j;
while(cin>>n)
{
for(int i=1;i<=n;i++)
{
cin>>a>>b>>c;
k=0;
for(j=(1000/a)*a;j<10000;j=j+a)
{
if((j+1)%b==0&&(j+2)%c==0)
{
k=1;
break;
}
}
if(k==1)
cout<<j<<endl;
else
cout<<"Impossible"<<endl;
}
}
return 0;

}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: