ZOJ-Crashing Balloon
Posted miyamochio
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ZOJ-Crashing Balloon相关的知识,希望对你有一定的参考价值。
1 #include <iostream> 2 using namespace std; 3 bool flagM, flagN; 4 void dfs(int m, int n, int factor){ 5 if (m == 1 && n == 1){//两个都被完全因式分解 6 flagM = flagN = true; 7 //printf("return; "); 8 return; 9 } 10 if (n == 1)//小数被分解完,大数还未被分解完 11 flagN = true; 12 while (factor>1){ 13 14 if (m%factor == 0) { 15 //printf("m:%d,factor:%d ", m, factor); 16 dfs(m / factor, n, factor - 1); 17 } 18 19 if (n%factor == 0) { 20 //printf("n:%dfactor:%d ",n,factor); 21 dfs(m, n / factor, factor - 1); 22 } 23 factor--; 24 } 25 } 26 int main(){ 27 int m, n; 28 while (cin>>m>>n){ 29 if (m<n){ 30 int t = m; 31 m = n; 32 n = t; 33 } 34 flagM = flagN = false; 35 dfs(m, n, 100); 36 if (!flagM && flagN) 37 cout << n << endl; 38 else 39 cout << m << endl; 40 } 41 return 0; 42 }
以上是关于ZOJ-Crashing Balloon的主要内容,如果未能解决你的问题,请参考以下文章