|
|
вернуться в форумNeed your HELP! Getting WA8! Послано tvd 3 июн 2012 00:23 Here's my solution, can't figure out, what's wrong, it passes all the tests I can think of. Help me, please. #include <iostream> #include <string> int state; long long base(int b, std::string str) { int size = str.size(); int i = 0; long long res = 0; while(i < size) { res *= b; if(str[i] >= 'A') str[i] -=7; str[i] -= 48; if(str[i] >= b) { state = 1; return b; } res += str[i]; ++i; } return res; } int main() { std::string str; std::cin >> str; for(int i = 2; i < 37; ++i) { state = 0;
if(base(i, str)%(i - 1) == 0 && !state) { std::cout << i << std::endl; return 0; } } std::cout << "No solution." << std::endl; return 0; } |
|
|