首页 > ACM题库 > HDU-杭电 > HDU 1562 Guess the number-数论-[解题报告] C++
2013
12-12

HDU 1562 Guess the number-数论-[解题报告] C++

Guess the number

问题描述 :

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 ?

输入:

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.

输出:

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".

样例输入:

2
44 38 49
25 56 3

样例输出:

Impossible
2575

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1562

题意:求最小的[1000,9999]区间内的数x满足x%a==0 && (x+1)%b==0 && (x+2)%c==0。

mark:应该是用剩余定理的,不过数据那么小,直接爆了。

代码:

# include <stdio.h>


int main ()
{
    int T, a, b, c, i ;
    scanf ("%d", &T) ;
    while (T--)
    {
        scanf ("%d%d%d", &a, &b, &c) ;
        for (i = 1000 ;  i<= 9999 ; i++)
            if (i%a == 0 && (i+1)%b == 0 && (i+2)%c==0) break ;
        if (i == 10000) puts ("Impossible") ;
        else printf ("%d\n", i) ;
    }
    return 0 ;
}

解题报告转自:http://www.cnblogs.com/lzsz1212/archive/2012/01/13/2322117.html


  1. 话说,想看火影的恋爱,最新的两个剧场版不就描写的鸣人和雏田恋爱么。还一个婚后生活的。当然了,主题不是日常恋爱,秀恩爱的时间肯定不多,不过也比这好多了。

  2. 这个方法是错的,不信你试试:
    20 5
    1 A:9
    1 A:9
    1 A:9
    1 A:6
    1 A:4
    正确答案应该是19,这个答案是18