HDU6063-RXD and math

来源:互联网 发布:网络主播怎么赚钱 编辑:程序博客网 时间:2024/06/04 21:06

RXD and math

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 448 Accepted Submission(s): 230

Problem Description
RXD is a good mathematician.
One day he wants to calculate:
∑i=1nkμ2(i)×⌊nki−−−√⌋

output the answer module 109+7.
1≤n,k≤1018
μ(n)=1(n=1)

μ(n)=(−1)k(n=p1p2…pk)

μ(n)=0(otherwise)

p1,p2,p3…pk are different prime numbers

Input
There are several test cases, please keep reading until EOF.
There are exact 10000 cases.
For each test case, there are 2 numbers n,k.

Output
For each test case, output “Case #x: y”, which means the test case number and the answer.

Sample Input
10 10

Sample Output
Case #1: 999999937

Source
2017 Multi-University Training Contest - Team 3

题目大意:计算题中式子
解题思路:打表找到规律n^k

打表代码:

#include<iostream>#include<cstdio>#include<cmath>using namespace std;typedef long long LL;int mu[100005];int MAXN=1e5;void init(){    mu[1]=1;    for(int i=1;i<=MAXN;i++)    {        for(int j=2*i;j<=MAXN;j+=i)        {            mu[j]-=mu[i];        }    }}int main(){    init();//    for(int i=1;i<=100;i++)//    {//        cout<<mu[i]<<" ";//    }    for(int i=1;i<=1000;i++)    {        int up=i;        LL ans=0;        for(int j=1;j<=up;j++)        {            ans+=(mu[j]*mu[j])*(int)(sqrt(i/j));        }        cout<<i<<": "<<ans<<endl;    }}

AC代码:

#include<iostream>#include<cstdio>#include<cmath>using namespace std;typedef long long LL;const LL MOD=1e9+7;LL quickpow(LL x,LL y){    LL res=1;    while(y)    {        if(y&1) res=(res*x)%MOD;        x=((x%MOD)*(x%MOD))%MOD;        y>>=1;    }    return res;}int main(){    LL n,k;    int cas=0;    while(scanf("%lld%lld",&n,&k)!=EOF)    {        printf("Case #%d: %lld\n",++cas,quickpow(n,k));    }}
原创粉丝点击