首页 技术 正文
技术 2022年11月14日
0 收藏 650 点赞 3,139 浏览 1124 个字

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6063

题目意思:字面意思,给出n,k,算出这个式子的答案。

思路:比赛的时候是打表找规律过了,赛后仔细研究一下数学上的具体做法,首先莫比乌斯函数,就是他后面给的那个式子μ(n)=(−1)k(n=p1p2…pk)   p1,p2,p3…pk是互不相同的的素数。满足这个条件的n,μ^2(n)=1,否则μ^2(n)=0;从这个定义里面我们发现所有满足μ^2(n)=0的n值必定满足n=a^2*b,其中μ^2(b)=1。我们建立一个这样不等式a^2*b<=n;变形以后得到a<=sqrt(n/b)。很明显如果a取整数,那么a可以等于1,2,3,4,5……floor(sqrt(n/b)),共floor(sqrt(n/b))项,满足任何一项的的莫比乌斯函数等于0的。所以每一个莫比乌斯函数的平方等于1的数乘上floor(sqrt((n/i))),相当于把后面因为他被而变成0的项给补上了。所以相当于每一项的值都是1,所以这个式子的答案就是n,至于给n^k完全就是为了,让你推出这个公式以后,考一下你快速幂姿势。

代码:

 //Author: xiaowuga
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <bitset>
#include <cctype>
#define maxx INT_MAX
#define minn INT_MIN
#define inf 0x3f3f3f3f
#define mem(s,ch) memset(s,ch,sizeof(s))
#define nc cout<<"nc"<<endl
const long long mod=1e9+;
using namespace std;
typedef long long LL;
LL q_power(LL a,LL k){
LL ans=;
a%=mod;
while(k){
if(k%) ans=(ans*a%mod+mod)%mod;
k/=;
a=(a*a%mod+mod)%mod;
}
return ans;
}
int main() {
ios::sync_with_stdio(false);cin.tie();
LL n,k,ca=;
while(cin>>n>>k){
cout<<"Case #"<<++ca<<": "<<q_power(n,k)%mod<<endl;
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,076
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,400
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,812
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,894