题目链接
http://codeforces.com/problemset/problem/664/A
题意
给两个数,找出它们的最大公因子d,使得从a到b之间的数都可以整除d.
题解
结论:
当gcd(a, b) = 1,则gcd(a + b, a) = 1
反证法:
假设gcd(a + b, b) = k != 1;
则: b = k * r1
a + b =a + k * r1 = k * R
两边同时除以k
a / k + r1 = R
则要使相等,则a 必须整除k, 则 a = k * r2;
所以gcd(a, b) = k != 1 与gcd(a, b) = 1矛盾
故假设不成立。
另一种证明思路:
gcd(1,a)=1, gcd(a,a)=a, gcd(a,a+1)=gcd(a,1)=1. ?
代码
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner in=new Scanner(System.in);
String a=in.next();
String b=in.next();
if(a==b) {
System.out.print(a);
}
else {
System.out.print("1");
}
}
}