Project Euler 题解 #48 Self Powers

题目:Self powers

The series, 11 + 22 + 33 + ... + 1010 = 10405071317.

Find the last ten digits of the series, 11 + 22 + 33 + ... + 10001000.

这个题意很明确,解决起来比较简单。

数学描述

代码实现

//https://projecteuler.net/problem=48
//Self powers
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <cmath>
#include <BaseTsd.h>

using namespace std;

//N:序列最大值
//M:保留的最末数字个数
INT64 SelfPower(int N, int M)
{
	INT64 sum = 0;
	INT64 base = (INT64)pow((double)10, int(M));
	for (int i = 1; i <= N; ++i)
	{
		INT64 product = 1;
		for (int j = 1; j <= i; ++j)
		{
			product *= i;
			product %= base;
		}
		sum += product;
		sum %= base;
	}
	return sum;
}

int _tmain(int argc, _TCHAR* argv[])
{
	int N = 1000, M = 10;
	INT64 ans = SelfPower(N, M);

	cout<<"SelfPower("<<N<<","<<M<<") = "<<ans<<endl;

	system("pause") ;
	return 0;
}

输入:N=1000,M=10

输出:SelfPower(1000,10) = 9110846700

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值