【欧拉计划 16】幂的数字和

题目描述:
215=32768,而3276832768的各位数字之和是3+2+7+6+8=263+2+7+6+8=26。

21000的各位数字之和是多少?

解法:高精度模拟

#include<bits/stdc++.h>
using namespace std;
int ans[1000];
int main(){
	ans[1]=2;
	for(int i=2;i<=1000;i++){
		for(int j=1;j<=1000;j++)ans[j]*=2;
		for(int j=1;j<=1000;j++){
			if(ans[j]>=10){
				ans[j+1]+=ans[j]/10;
				ans[j]%=10;
			}
		}
		//for(int i=1;i<=20;i++)printf("%d",ans[i]);
		//system("pause");
	}
	int res=0;
	for(int i=1;i<=1000;i++){
		res+=ans[i];
	}
	cout<<res<<endl;
	return 0;
}
posted @ 2022-05-08 10:36  计算机知识杂谈  阅读(64)  评论(0编辑  收藏  举报