标签:ace 状态 cout highlight 初始 div ons tno for
#include <iostream> #include <vector> using namespace std; const int MAX_LEN = 10000; int main() { int n = 0; //3^n的最大位数是:10000,乘一次3就加一位 while (cin >> n) { //初始状态 vector<int> res(MAX_LEN, 0); res[0] = 1; //大数乘法 while (n--) { for (int i = 0; i < MAX_LEN - 1; ++i) { res[i] *= 3; } for (int i = 0; i < MAX_LEN - 1; ++i) { res[i + 1] += res[i] / 10; res[i] %= 10; } } ++res[0]; // 3^n + 1 for (int i = 0; i < MAX_LEN - 1; ++i) { res[i + 1] += res[i] / 10; res[i] %= 10; } //大数除2,从高位开始 for (int i = MAX_LEN - 1; i > 0; --i) { res[i - 1] += 10 * (res[i] % 2); res[i] /= 2; } res[0] /= 2; bool bMeetNoZero = false; for (int i = MAX_LEN - 1; i >= 0; --i) { if (bMeetNoZero) { cout << res[i]; } else { if (res[i] != 0) { cout << res[i]; bMeetNoZero = true; } } } cout << endl; } return 0; }
标签:ace 状态 cout highlight 初始 div ons tno for
原文地址:https://www.cnblogs.com/XPHouse/p/12771024.html