HDU 2879
利用x<n的信息,可以证得当n为素数时,he[n]=2;同时,若n 为素数,则有HE[N^K]=2;因为若等式成立则有n|x(x-1)。抓住这个证即可。
至于符合积性函数,想了很久也没想出来,看了看网上的,觉得是不对的。
但试过几个数后,确实符合积性函数,就当是猜想吧。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#define LL __int64
using namespace std; const LL N=10000005; bool isprime[N];
int pme[N],np; void initial(){
memset(isprime,true,sizeof(isprime));
np=0;
isprime[1]=false;
for(LL i=2;i<N;i++){
if(isprime[i]){
pme[np++]=i;
for(LL j=i*i;j<N;j+=i){
isprime[j]=false;
}
}
}
} LL work(LL n){
LL rs=0;
for(int i=0;i<np&&pme[i]<=n;i++){
rs+=(n/pme[i]);
}
return rs;
} LL quick(LL a,LL b,LL m){
LL res=1;
while(b){
if(b&1)
res=(res*a)%m;
b>>=1;
a=(a*a)%m;
}
return res;
} int main(){
LL n,m;
int T;
initial();
scanf("%d",&T);
while(T--){
scanf("%I64d%I64d",&n,&m);
LL k=work(n);
LL ans=quick((LL)2,k,m);
printf("%I64d\n",ans);
}
return 0;
}
HDU 2879的更多相关文章
- 积性函数,线性筛入门 HDU - 2879
HDU - 2879HeHe 题意:He[N]为[0,N−1]范围内有多少个数满足式子x2≡x (mod N),求HeHe[N]=He[1]×……×He[N] 我是通过打表发现的he[x]=2k,k为 ...
- HDU 2879 数论
HeHe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submis ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- codevs 2879 堆的判断
codevs 2879 堆的判断 http://codevs.cn/problem/2879/ 题目描述 Description 堆是一种常用的数据结构.二叉堆是一个特殊的二叉树,他的父亲节点比两个儿 ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- BZOJ 2879: [Noi2012]美食节
2879: [Noi2012]美食节 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1834 Solved: 969[Submit][Status] ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- 初探swift语言的学习笔记十(block)
作者:fengsh998 原文地址:http://blog.csdn.net/fengsh998/article/details/35783341 转载请注明出处 假设觉得文章对你有所帮助,请通过留言 ...
- Ambari-单步创建cluster
Ambari-单步创建 总体介绍 单步创建集群即对于集群内每个服务的安装.开启.组成服务的每个组件host信息的设置等操作都进行一次ambari-server的restAPI的调用. 这样做提高了对集 ...
- 开发效率必备之Mac双屏显示
自从2015年9月苹果公布EI Captain,带来了一个新的功能,叫做分屏,也就是在一块屏幕上分成左右两部分,能够分别进行操作,互不影响. 例如以下图所看到的: watermark/2/text/a ...
- (素数求解)I - Dirichlet's Theorem on Arithmetic Progressions(1.5.5)
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit cid=1006#sta ...
- h5-登录
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- lightoj--1294--Positive Negative Sign(水题,规律)
Positive Negative Sign Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu ...
- Vmware 安装samba
samba是什么samba是什么?能干什么? samba 是基于SMB协议(ServerMessage Block,信息服务块)的开源软件,samba也可以是SMB协议的商标.SMB是一种Linux. ...
- 客户现场调试(连接oracle数据库)
1.System.Data.OracleClient 需要 Oracle 客户端软件 8.1.7 或更高版本 http://blog.csdn.net/yucaoye/article/details/ ...
- ubuntu 绘制lenet网络结构图遇到的问题汇总
Couldn't import dot_parser, loading of dot files will not be possible的问题 1 .sudo pip uninstall pypar ...
- layer最大话.最小化.还原回调方法使用
<head> <meta charset="UTF-8"> <title>layer最大话.最小化.还原回调方法使用</title> ...