首页 > 编程知识 正文

HDU6063RXD and math

时间:2023-05-05 20:42:16 阅读:223028 作者:145

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 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: %lldn",++cas,quickpow(n,k)); }}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。