HDOJ(HDU) 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;...

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

枚举就可以了。。

import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            boolean is = true;
            int tm=a;
            while(a<1000){
                a=a+tm;
            }

            //注意!答案的范围是[1000,9999]
            for (int i = a; i < 10000; i = i + tm) {
                //此处注意i是加tm,而不是再加a了,因为a可能变了。
                if ((i+1)%b==0&&(i+2)%c==0) {
                    System.out.println(i);
                    is = false;
                    break;
                }
            }

            if (is) {
                System.out.println("Impossible");
            }

        }
    }

}
目录
相关文章
HDOJ(HDU) 2113 Secret Number(遍历数字位数的每个数字)
HDOJ(HDU) 2113 Secret Number(遍历数字位数的每个数字)
91 0
HDOJ(HDU) 1562 Guess the number(水题,枚举就行)
HDOJ(HDU) 1562 Guess the number(水题,枚举就行)
97 0
HDOJ 1391 Number Steps(打表DP)
HDOJ 1391 Number Steps(打表DP)
98 0
HDOJ 1391 Number Steps(打表DP)
HDOJ 1266 Reverse Number(数字反向输出题)
HDOJ 1266 Reverse Number(数字反向输出题)
87 0
|
Java
HDOJ 1018 Big Number(大数位数公式)
HDOJ 1018 Big Number(大数位数公式)
83 0
HDOJ 1005 Number Sequence
HDOJ 1005 Number Sequence
79 0
|
前端开发
HDOJ 1212 Big Number
HDOJ 1212 Big Number
84 0
|
小程序 C语言
【入门级C语言程序 -- 猜数字】Guess Number Game
【入门级C语言程序 -- 猜数字】Guess Number Game
219 0
【入门级C语言程序 -- 猜数字】Guess Number Game
|
Java
HDOJ 1018 Big Number(大数位数公式)
Problem Description In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc.
899 0
HDOJ 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.
837 0