#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<list>
#include<stack>
#include<cstdio>
#include<fstream>
#include<numeric>
#include<functional>
#include<utility>
#include<memory>
#include<iomanip>
using namespace std;
int n, m;
bool flagA, flagB;
void dfs(int n,int m,int k){
if (n == 1 && m == 1){
flagA = true;
flagB = true;
return;
}
if (m == 1){
flagB = true;
}
for (int t = k + 1; t <= 100; t++){
if (n%t == 0){
dfs(n/t,m,t);
if (flagA) return;
}
if (m%t == 0){
dfs(n, m / t,t);
if (flagA) return;
}
}
}
int main(){
while (cin >> n >> m){
if (n < m){
swap(n, m);
}
flagA = false;
flagB = false;
dfs(n,m,1);
int res = n;
if (flagA == false && flagB == true){
res = m;
}
cout << res << endl;
}
return 0;
}
ZOJ 1003 Crashing Balloon
最新推荐文章于 2022-03-10 14:37:07 发布