2018 GCPC A题:Chika‘s Math Homework

题意i的平方*(在n中取i)     i从0到n   累加


推导公式,组合数学。


原创代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll pow_mod(ll a,ll n,ll m)
{
	if(n==0)
		return 1;
	ll x=pow_mod(a,n/2,m);
	ll ans=x*x%m;
	if(n%2==1)
		ans=ans*a%m;
	return ans;
}
int main()
{
	ll n,d=1000000007;
	ll sum=0;
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lld",&n);
		sum=pow_mod(2,n-1,d);
		sum=(((n%d)*((n+1)%d))/2%d*(sum%d)%d);
		printf("%lld\n",sum);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_40295575/article/details/80216435