2017 Multi-University Training Contest - Team 3——HDU6063 RXD and math
题目链接: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 ;
}
2017 Multi-University Training Contest - Team 3——HDU6063 RXD and math的更多相关文章
- 【2017 Multi-University Training Contest - Team 3】RXD and math
[Link]: [Description] [Solution] 发现1010mod(109+7)=999999937; 猜测答案是nk 写个快速幂; 注意对底数先取模; [NumberOf WA] ...
- 2017 Multi-University Training Contest - Team 3 hdu6060 RXD and dividing
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6060 题目: RXD and dividing Time Limit: 6000/3000 M ...
- 【2017 Multi-University Training Contest - Team 3】RXD's date
[Link]: [Description] [Solution] [NumberOf WA] 1 [Reviw] [Code] #include <bits/stdc++.h> using ...
- 2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】
FFF at Valentine Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】
Dying Light Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tot ...
- 2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】
CSGO Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- 2017 Multi-University Training Contest - Team 9 1002&&HDU 6162 Ch’s gift【树链部分+线段树】
Ch’s gift Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- 2017 Multi-University Training Contest - Team 9 1001&&HDU 6161 Big binary tree【树形dp+hash】
Big binary tree Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- 2017 Multi-University Training Contest - Team 1 1003&&HDU 6035 Colorful Tree【树形dp】
Colorful Tree Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
随机推荐
- hdu 4217Data Structure?
树状数组+二分 就是找第几小的数,,找几次,再求和. . #include<cstdio> #include<cstring> #include<iostream> ...
- Memcached安装以及PHP的调用
Memcached安装以及PHP的调用 [南京·10月17日]OSC源创会开始报名:Swift.大型移动项目构架分享 » 一:安装libevent 由于memcached安装时,需要使用libeven ...
- iptables安装失败后-------------firewalld回归
yum install firewalld systemctl stop iptables; systemctl mask iptables; systemctl unmask firewalld s ...
- deb包的2种安装安装方法
一.cydia重启自动安装:用ifunbox进入//var/root/Media/Cydia/AutoInstallCydia/AutoInstall 需要分别单独建立,注意大小写.然后把你要安装的d ...
- c函数声明前加typedef是什么情况
刚才看到APUE(高级UNIX环境编程)里面的apue.h中有一行 typedef void Sigfunc(int); 没搞懂什么意思 其实就是定义一个函数指针类型,等价于 typedef void ...
- 读取SD卡中的图片
Touxiang=(ImageView)view.findViewById(R.id.Touxiang); //头像Bitmap bm = BitmapFactory.decodeFile(" ...
- R ggplot2 改变颜色
p<-ggplot(iris,aes(Petal.Length,Petal.Width,color=Species))+geom_point()cols=c("red",&q ...
- jquery 排除重复
应用场景——双盒选择器 两个select可能会出现重复的情况 排除重复代码如下: /** * 删除$fromGroup中与$toGroup重复的option * @param $fromGroup = ...
- xeno 实时性能测试 在100us的采样周期的测试数据
1 xeno 用户层测试时间: root@sama5d3-linux:/usr/bin latency -t0 -T25 -p100== Sampling period: 100 us== Test ...
- springmvc+shiro认证框架配置
1,在web.xml中配置fiter,如下所示 <!-- shiro的filter --> <!-- shiro过虑器,DelegatingFilterProxy通过代理模式将spr ...