fork download
  1. #include <iostream>
  2. using namespace std;
  3. int a,b,n;
  4. int main(){
  5. cin >> a >> b;
  6. if(max(a,b)%min(a,b) == 0) n = min(a,b);
  7. else for(int i = 1; i <= min(a,b); i++)
  8. if(a%i == 0 && b%i == 0)
  9. n = i;
  10. cout<<n;
  11. }
Success #stdin #stdout 0.01s 5464KB
stdin
12 42
stdout
6