1562 Guess the number
2016-03-12 21:57
225 查看
[align=left]Problem Description[/align]
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 ?
[align=left]Input[/align]
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.
[align=left]Output[/align]
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".
[align=left]Sample Input[/align]
2
44 38 49
25 56 3
[align=left]Sample Output[/align]
Impossible
2575
View Code
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 ?
[align=left]Input[/align]
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.
[align=left]Output[/align]
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".
[align=left]Sample Input[/align]
2
44 38 49
25 56 3
[align=left]Sample Output[/align]
Impossible
2575
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; int main() { int a,b,c,n,k,j; while(cin>>n) { for(int i=1;i<=n;i++) { cin>>a>>b>>c; k=0; for(j=(1000/a)*a;j<10000;j=j+a) { if((j+1)%b==0&&(j+2)%c==0) { k=1; break; } } if(k==1) cout<<j<<endl; else cout<<"Impossible"<<endl; } } return 0; }
View Code
相关文章推荐
- 625A.Guest From the Past
- 62. 63. Unique Paths 64. Minimum Path Sum
- 设计模式-Builder模式
- JavaSE入门学习29:Java常用类之StringBuffer类和StringBuilder类
- UIImage
- Java 1.6 AbstractQueuedSynchronizer源码解析
- UIScrollViewDelegate
- 626A.Robot Sequence
- UICollectionView
- AJAX async:true(异步)或 false(同步)。
- iOS-UIScrollView和UIPageControl的综合实力,滚动图,轮播图
- java selenium (九) 常见web UI 元素操作 及API使用
- iOS— UIScrollView和 UIPageControl之间的那些事
- iOS 常用UI 部分常用 方法
- UIScrollView的属性总结
- android 6.0 SystemUI源码分析(5)-PowerUI介绍
- Infinite Sequence
- MFC-GUI绘图相关摘要
- UITextField
- 省市便利 UIPicherView