You are viewing a single comment's thread. Return to all comments →
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int wut[10000]; void Shift(int arr[], int arrsize){ for(int i = arrsize - 1; i >= 0; i--){ arr[i+1] = arr[i]; } } void Pre(int arr[],int n){ arr[0] = 1; int arrsize = 1; int j = 0; while(n > 0){ for(int i = 0; i < arrsize; i++){ arr[i] = arr[i]*2; if(i == 0) continue; else if(arr[i] >= 10){ arr[i-1] += arr[i] / 10; arr[i] %= 10; } } while(arr[0] >= 10){ int temp = arr[0] / 10; arr[0] %= 10; Shift(arr, arrsize); arrsize++; arr[0] = temp; } int tong = 0; for(int i = 0; i < arrsize; i++){ tong += arr[i]; } wut[j] = tong; j++; n--; } } int main() { int t; int arr[3012]; Pre(arr, 10000); scanf("%d", &t); for(int a0 = 0; a0 < t; a0++ ){ int n; scanf("%d", &n); printf("%d\n",wut[n-1]); } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #16: Power digit sum
You are viewing a single comment's thread. Return to all comments →