本文共 1245 字,大约阅读时间需要 4 分钟。
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8304 | Accepted: 3792 |
Description
Input
Output
Sample Input
100254
Sample Output
4181461
Source
#include#include #include int arr[10000100];void init(){ int x2, x3; int i; x2 = x3 = 1; arr[1] = 1; for (i = 2; i <= 10000000; i++){ arr[i] = (2 * arr[x2] + 1) < (3 * arr[x3] + 1) ? (2 * arr[x2] + 1) : (3 * arr[x3] + 1); if (arr[i] == 2 * arr[x2] + 1){ x2 ++; } if (arr[i] == 3 * arr[x3] + 1){ x3 ++; } }}int main(void){ int n; init(); while (scanf("%d", &n) != EOF){ printf("%d\n", arr[n]); }}
转载地址:http://qooji.baihongyu.com/