欧拉计划 第十六题

215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 21000?

2 15 = 32768,其数字之和为3 + 2 + 7 + 6 + 8 = 26。

数字2 1000的数字总和是多少?

思路

1.大数相乘,只需将大数相加中的加法改成乘法即可

#include <stdio.h>

int main(){
	int mul[400] = {0};
	mul[0] = mul[1] = 1;
	for(int i = 0; i < 1000; i++){
		for(int j = 1; j <= mul[0]; j++){
			mul[j] *= 2;
		}
		for(int j = 1; j <= mul[0]; j++){
			if(mul[j] < 10) continue;
			mul[j + 1] += mul[j] / 10;
			mul[j] %= 10; 
			mul[0] += (mul[0] == j);
		}
	}
	int ans = 0;
	for(int i = 1; i <= mul[0]; i++){
		ans += mul[i];
	}
	printf("%d\n", ans);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_38362049/article/details/80958288