1562 Guess the number

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 ?

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

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 using namespace std;
 5
 6 int main()
 7 {
 8      int a,b,c,n,k,j;
 9      while(cin>>n)
10      {
11          for(int i=1;i<=n;i++)
12          {
13              cin>>a>>b>>c;
14              k=0;
15              for(j=(1000/a)*a;j<10000;j=j+a)
16              {
17                  if((j+1)%b==0&&(j+2)%c==0)
18                  {
19                      k=1;
20                      break;
21                  }
22              }
23              if(k==1)
24              cout<<j<<endl;
25              else
26              cout<<"Impossible"<<endl;
27          }
28      }
29      return 0;
30
31 }

时间: 2024-10-13 10:42:46

1562 Guess the number的相关文章

HDU 1562 Guess the number

题目链接: 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 be

杭电 HDU ACM 1562 Guess the number

Guess the number Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3035    Accepted Submission(s): 2281 Problem Description Happy new year to everybody! Now, I want you to guess a minimum  number

PKU 1562/HDU 1241 Oil Deposits(原油有多少块区域---BFS,DFS)

Oil Deposits Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region o

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

17. Letter Combinations of a Phone Number

Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit string "23" Output: ["ad", "ae", &q

实现一个函数clone,使JavaScript中的5种主要的数据类型(包括Number、String、Object、Array、Boolean)进行值复制

实现一个函数clone,可以对JavaScript中的5种主要的数据类型(包括Number.String.Object.Array.Boolean)进行值复制. 1 /** 对象克隆 2 * 支持基本数据类型及对象 3 * 递归方法 */ 4 function clone(obj) { 5 var o; 6 switch (typeof obj) { 7 case "undefined": 8 break; 9 case "string": o = obj + &q

解决sqoop报错Invalid number; item = ITEM_UNICODE

报错栈: java.sql.SQLException: Invalid number; item = ITEM_UNICODE at com.intersys.jdbc.SysList.getInt(SysList.java:1735) at com.intersys.jdbc.CacheResultSet.getInt(CacheResultSet.java:247) at org.apache.sqoop.lib.JdbcWritableBridge.readInteger(JdbcWrit

1005 Number Sequence

Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n). Input The input consists of multiple test cases. Each test case co

Minimum Inversion Number 【线段数】

Problem DescriptionThe inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i < j and ai > aj. For a given sequence of numbers a1, a2, ..., an, if we move the first m >= 0 numbers to the end of