湖南多校对抗赛3.28 J - Jerry's trouble

Problem J: Jerry's trouble

Time Limit: 10 Sec  Memory Limit: 256 MB
Submit: 96  Solved: 46
[Submit][Status][Web Board]

Description

 Jerry is caught by Tom. He was penned up in one room with a door, which only can be opened by its code. The code is the answer of the sum of the sequence of number written on the door. The type of the sequence of number is

 

But Jerry’s mathematics is poor, help him to escape from the room.

Input

 There are some cases (about 500). For each case, there are two integer numbers n, m describe as above ( 1 <= n < 1 000 000, 1 <= m < 1000).

Output

 For each case, you program will output the answer of the sum of the sequence of number (mod 1e9+7).

Sample Input

4 1
5 1
4 2
5 2
4 3

Sample Output

10
15
30
55
100

HINT

题意:给你一个n和一个m,求1-n每个数的m次方的和;
简单的快速矩阵幂,但是因为没有看清题目要求,输入输出都写成了I64d导致一直PE,改成lld就AC了。
代码如下:
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
long long int q=1e9+7;
long long int mix(long long int a, long long int m)
{
	if(m==0) return 1;
	long long int sum=1;
	while(m)
	{
		if(m%2)
			sum=(sum*a) % q;
		a=(a*a)%q;
		m/=2;
	}
	return sum;
}

int main()
{
	long long int n=0, m=0;
	while(scanf("%lld%I64d", &n, &m)!=EOF)
	{
		long long int ans=0;
		for(int i=1; i<=n; i++)
		{
			ans=(ans+mix(i,m))% q;
		}
		printf("%lld\n", ans);
	}
	return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值