#include<bits/stdc++.h> using namespace std; int main() { int a, b, i=1, t=0; cin >> a >> b; while (i <= a i <= b) { if (a % i == 0 && b % i == 0) { t = i; } i++; } cout << t << endl; return 0; }
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
import java.util.Scanner;
public class c3 { public static void main(String[] args) { Scanner prime = new Scanner(System.in); int i=1, t=0; int a = prime.nextInt(); int b =prime.nextInt(); while (i <= a i <= b) { if (a % i == 0 && b % i == 0) { t = i; } ++i; } System.out.println(t); } }