您的位置:首页 > 其它

ZOJ 1003 Crashing Balloon

2017-05-20 23:07 405 查看
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: