题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1562
Problem Description
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 ?
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 ?
Input
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.
Output
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".
Sample Input
2
44 38 49
25 56 3
Sample Output
Impossible
2575
Author
8600
1 #include<stdio.h> 2 #include<iostream> 3 using namespace std; 4 int main() 5 { 6 int T; 7 int a,b,c,x; 8 bool flag1,flag2,flag3; 9 cin>>T; 10 while(T--) 11 { 12 cin>>a>>b>>c; 13 flag1=false;flag2=false;flag3=false; 14 for(x=1000;x<=9999;x++)//预处理防止超时 15 { 16 if(x%a==0) 17 { 18 flag1=true; 19 break; 20 } 21 } 22 if(flag1) 23 { 24 for(;x<=9999;x+=a) 25 { 26 if((x+1)%b==0&&(x+2)%c==0) 27 { 28 flag2=true; 29 cout<<x<<endl; 30 break; 31 } 32 } 33 } 34 if(!flag2) 35 cout<<"Impossible"<<endl; 36 } 37 return 0; 38 }