4427. Greatest Common Divisors
来源:互联网 发布:动漫图片制作软件 编辑:程序博客网 时间:2024/06/07 03:02
4427. Greatest Common Divisors
Constraints
Time Limit: 5 secs, Memory Limit: 256 MB
Description
A common divisor for two positive numbers is a number which both numbers are divisible by. It's easy to calculate the greatest common divisor between tow numbers. But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low<=d<=high. It is possible that there is no common divisor in the given range.
Input
The first line contains an integer T (1<=T<=10)- indicating the number of test cases.
For each case, there are four integers a, b, low, high (1<=a,b<=1000,1<=low<=high<=1000) in one line.
Output
For each case, print the greatest common divisor between a and b in given range, if there is no common divisor in given range, you should print “No answer”(without quotes).
Sample Input
3
9 27 1 5
9 27 10 11
9 27 9 11
Sample Output
3
No answer
9
Problem Source
2011年新手赛Warm Up by AcFast
// Problem#: 4427
// Submission#: 1984637
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main(){
int T,i;
cin>>T;
for(i=0;i<T;i++){
int a, b, low, high;
cin>>a>>b>>low>>high;
int x,temp=0;
for(x=low;x<=high;x++){
if((a%x)==0&&(b%x)==0){
temp=x;
}
}
if(temp==0){
cout<<"No answer"<<endl;
}
else{
cout<<temp<<endl;
}
}
return 0;
}
- 4427. Greatest Common Divisors
- 4427. Greatest Common Divisors
- Sicily 4427. Greatest Common Divisors
- Sicily 4427. Greatest Common Divisors
- <OJ_Sicily>Greatest Common Divisors
- <Sicily>Greatest Common Divisors
- Greatest common divisors & Fibonacci Numbers--Algorithms
- Greatest Greatest Common Divisor
- Common Divisors
- Greatest Greatest Common Divisor HD5207
- Greatest common divisor
- The Greatest Common Divisor
- GCD (Greatest Common Divisor)
- Greatest Common Increasing Subsequence
- Solving Greatest Common Divisor
- the greatest common divisor
- 最大公约数Greatest Common Divisor
- Greatest common divider
- win7下Documents and Settings拒绝访问的解决方法
- {嵌入式stm32}之关于GPIO的输入输出
- 面试题开发实战
- mac下用vim打造python IDE之二 —— Taglist插件
- 给gloox加上支持接收好友更新头像的信息
- 4427. Greatest Common Divisors
- 装饰设计模式_装饰和继承的区别_字节流_读取键盘录入
- R语言与非参数统计(核密度估计)
- BIOS
- 3499. 分数统计
- 黑马程序员java学习第一天,基础篇
- 消除JMVC中的warning
- 3712. Matrix multiplication
- 黑马程序员java学习第二天,java入门介绍