HDU 1562 Guess the number

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1562

Problem Descriptionhappy New Year to everybody!
Now, I want your to guess a minimum number x BETWWN and 9999
(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's the number of x?
Inputthe Number of test cases C is in the first line of input, then C test Cases Followed.every test contains three intege Rs A, B, C.
Outputfor each test case your program should output one and the minimal number x, you should remember that X is BETW Een and 9999. If There is no answer for X, Output "impossible".
Sample Input244 38 4925 56 3
Sample OutputImpossible2575
Author8600

1#include <stdio.h>2#include <iostream>3 using namespacestd;4 intMain ()5 {6     intT;7     inta,b,c,x;8     BOOLFlag1,flag2,flag3;9Cin>>T;Ten      while(t--) One     { ACin>>a>>b>>C; -flag1=false; flag2=false; flag3=false; -          for(x= +; x<=9999; x + +)//preprocessing prevents timeouts the         { -             if(x%a==0) -             { -flag1=true; +                  Break; -             } +         } A         if(FLAG1) at         { -              for(; x<=9999; x+=a) -             { -                 if((x+1)%b==0&& (x+2)%c==0) -                 { -Flag2=true; incout<<x<<Endl; -                      Break; to                 } +             } -         } the         if(!Flag2) *cout<<"Impossible"<<Endl; $     }Panax Notoginseng     return 0; -}

HDU 1562 Guess the number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.