Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一开始以为要写高精度,没想到连long long int都不用就AC了也是没谁了~ #include <iostream> using namespace std; bool state[101] = {false}; int mx(int a, int b){ if(a > b) return a; return b; } void init(){ for(int i = 0; i <= 100; i++) state[i] = false; } bool can(int a, int b, int mxa, int mxb){ if(a == 1 && b == 1) return true; if(a > 1 && mxa <= 1) return false; if(b > 1 && mxb <= 1) return false; int mxx = mx(mxa, mxb); for(int i = mxx; i >= 2; i--){ if(i <= mxa && state[i] == false && a%i == 0){ state[i] = true; if(can(a/i, b, i-1, mxb)) return true; state[i] = false; } if(i <= mxb && state[i] == false && b%i == 0){ state[i] = true; if(can(a, b/i, mxa, i-1)) return true; state[i] = false; } } return false; } int main() { int a, b; while(cin >> a >> b){ init(); if(a == 0 && b == 0) return 0; if(a > b){ int temp = a; a = b; b = temp; } //cout << can(a, b, 100, 100) << endl; //cout << can(a, 1, 100, 1) << endl; if(can(a, b, 100, 100)) cout << b << endl; else if(can(a, 1, 100, 1)) cout << a << endl; else cout << b << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator