hdu 6169 Senior PanⅡ Miller_Rabin素数测试+容斥
Senior PanⅡ
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)

Senior Pan had just failed in his math exam, and he can only prepare to make up for it. So he began a daily task with Master Dong, Dong will give a simple math problem to poor Pan everyday.
But it is still sometimes too hard for Senior Pan, so he has to ask you for help.
Dong will give Pan three integers L,R,K every time, consider all the positive integers in the interval [L,R], you’re required to calculate the sum of such integers in the interval that their smallest divisor (other than 1) is K.
Then T lines, each contains three integers L,R,K(1≤L≤R≤10^11,2≤K≤10^11)
1 20 5
2 6 3
Case #2: 3
占坑;。。。其实是不想写,容斥我用莫比乌斯函数推出来的
突然发现我sb,为什么写大素数测试啊。。。
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- #include<iostream>
- #include<cstdio>
- #include<cmath>
- #include<string>
- #include<queue>
- #include<algorithm>
- #include<stack>
- #include<cstring>
- #include<vector>
- #include<list>
- #include<bitset>
- #include<set>
- #include<map>
- using namespace std;
- #define LL long long
- #define pi (4*atan(1.0))
- #define eps 1e-8
- #define bug(x) cout<<"bug"<<x<<endl;
- const int N=3e3+,M=1e6+,inf=1e9+;
- const LL INF=1e18+,mod=1e9+;
- LL gcd(LL a, LL b)
- {
- return b? gcd(b, a % b) : a;
- }
- LL multi(LL a, LL b, LL m)
- {
- LL ans = ;
- a %= m;
- while(b)
- {
- if(b & )
- {
- ans = (ans + a) % m;
- b--;
- }
- b >>= ;
- a = (a + a) % m;
- }
- return ans;
- }
- LL quick_mod(LL a, LL b, LL m)
- {
- LL ans = ;
- a %= m;
- while(b)
- {
- if(b & )
- {
- ans = multi(ans, a, m);
- b--;
- }
- b >>= ;
- a = multi(a, a, m);
- }
- return ans;
- }
- const int Times = ;
- bool Miller_Rabin(LL n)
- {
- if(n == ) return true;
- if(n < || !(n & )) return false;
- LL m = n - ;
- int k = ;
- while((m & ) == )
- {
- k++;
- m >>= ;
- }
- for(int i=; i<Times; i++)
- {
- LL a = rand() % (n - ) + ;
- LL x = quick_mod(a, m, n);
- LL y = ;
- for(int j=; j<k; j++)
- {
- y = multi(x, x, n);
- if(y == && x != && x != n - ) return false;
- x = y;
- }
- if(y != ) return false;
- }
- return true;
- }
- int vis[M];
- vector<int>pri;
- void init()
- {
- for(int i=;i<=;i++)
- {
- if(!vis[i])
- pri.push_back(i);
- for(int j=i+i;j<=;j+=i)
- vis[j]=;
- }
- }
- LL out;
- void dfs(LL p,int pos,int step,LL L,LL R,LL K)
- {
- if(p*K>R)return;
- LL d=p*K;
- LL x1=(R/d),x2=(L-)/d;
- //cout<<p<<" "<<d<<" "<<step<<endl;
- //cout<<p<<" "<<pos<<" "<<step<<endl;
- if(step%==)
- {
- out+=((multi(x1,x1+,mod)*1LL*)%mod)*d;
- out%=mod;
- out-=((multi(x2,x2+,mod)*1LL*)%mod)*d;
- out=(out%mod+mod)%mod;
- }
- else
- {
- out-=((multi(x1,x1+,mod)*1LL*)%mod)*d;
- out=(out%mod+mod)%mod;
- out+=((multi(x2,x2+,mod)*1LL*)%mod)*d;
- out%=mod;
- }
- for(int i=pos;i<pri.size();i++)
- {
- if(pri[i]>=K)return;
- if(p*pri[i]*K>R)return;
- dfs(p*pri[i],i+,step+,L,R,K);
- }
- }
- int main()
- {
- init();
- int T,cas=;
- scanf("%d",&T);
- while(T--)
- {
- out=;
- LL l,r,k;
- scanf("%lld%lld%lld",&l,&r,&k);
- bool isp=Miller_Rabin(k);
- printf("Case #%d: ",cas++);
- if(!isp){
- printf("0\n");
- continue;
- }
- if(k>=)
- {
- if(l<=k&&r>=k)printf("%lld\n",k%mod);
- else printf("%lld\n",);
- }
- else
- {
- dfs(,,,l,r,k);
- printf("%lld\n",out);
- }
- }
- return ;
- }
hdu 6169 Senior PanⅡ Miller_Rabin素数测试+容斥的更多相关文章
- 2017多校第9场 HDU 6169 Senior PanⅡ 数论,DP,爆搜
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6169 题意:给了区间L,R,求[L,R]区间所有满足其最小质数因子为k的数的和. 解法: 我看了这篇b ...
- 数论 - Miller_Rabin素数测试 + pollard_rho算法分解质因数 ---- poj 1811 : Prime Test
Prime Test Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 29046 Accepted: 7342 Case ...
- Miller_Rabin 素数测试
费马定理的逆定理几乎可以用来判断一个数是否为素数,但是有一些数是判断不出来的,因此,Miller_Rabin测试方法对费马的测试过程做了改进,克服其存在的问题. 推理过程如下(摘自维基百科): 摘自另 ...
- Miller_Rabin素数测试【学习笔记】
引语:在数论中,对于素数的研究一直就很多,素数测试的方法也是非常多,如埃式筛法,6N±1法,或者直接暴力判(试除法).但是如果要判断比较大的数是否为素数,那么传统的试除法和筛法都不再适用.所以我们需要 ...
- HDU 6166 Senior Pan (最短路变形)
题目链接 Problem Description Senior Pan fails in his discrete math exam again. So he asks Master ZKC to ...
- HDU 6166.Senior Pan()-最短路(Dijkstra添加超源点、超汇点)+二进制划分集合 (2017 Multi-University Training Contest - Team 9 1006)
学长好久之前讲的,本来好久好久之前就要写题解的,一直都没写,懒死_(:з」∠)_ Senior Pan Time Limit: 12000/6000 MS (Java/Others) Memor ...
- HDU 6166 Senior Pan 二进制分组 + 迪杰斯特拉算法
Senior Pan Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Probl ...
- HDU How many integers can you find 容斥
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU - 4336:Card Collector(min-max容斥求期望)
In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, fo ...
随机推荐
- Symfony2学习笔记之事件分配器
----EventDispatcher组件使用 简介: 面向对象编程已经在确保代码的可扩展性方面走过了很长一段路.它是通过创建一些责任明确的类,让它们之间变得更加灵活,开发者可以通过继承这 ...
- 怎样从外网访问内网WampServer?
本地安装了一个WampServer,只能在局域网内访问,怎样从外网也能访问到本地的WampServer呢?本文将介绍具体的实现步骤. 准备工作 安装并启动WampServer 默认安装的WampSer ...
- Linux网络管理(一):网卡驱动与Linux内核
下图简单描述了网卡驱动与Linux内核之间的联系: 关于上图的一些说明: 系统初始化: 1. 协议模块调用 dev_add_pack() 来注册协议处理函数到链表 &ptype_base: 2 ...
- close yield
close的方法主要是关闭子生成器,需要注意的有4点: 1.如果生成器close后,还继续next,会报错StopIteration [图片] 2.如果我捕获了异常,将GeneratorE ...
- 微信企业号OAuth2.0验证接口来获取成员的身份信息
<?php $appid = "请输入您企业的appid"; $secret = "请输入您企业的secreat"; if (!isset($_GET[' ...
- Windows系统中设置Python程序定时运行方法
Windows系统中设置Python程序定时运行方法 一.环境 win7 + Python3.6 二.步骤 1,在Windows开始菜单中搜索“计划任务”,并且点击打开“计划任务”: 2.点击“创建基 ...
- spring @Value注解#和$区别
一直以来,在使用@Value注解的时候,都是使用#的风格@Value("#{topic.topicName}"),但是也经常会看到@Value("${topic.topi ...
- 实现 AD 采样,使用 LCD1602 显示 AD 数值
实现 AD 采样,使用 LCD1602 显示 AD 数值 写在前面 单片机内集成的A/D转换,一般都有相应的特殊功能寄存器来设置A/D的使能标志,参考电压,转换频率,通道选择,A/D输入口的属性(模拟 ...
- kali meterpreter中mimikatz模块获取密码
kali这方面不说了, meterpreter也略过, 做个关于mimikatz的笔记. mimikatz模块, 能获取对方机器的密码(包括哈希和明文). 渗透模块怎么进的也不说了, 方式太多, 我用 ...
- python简说(十)json模块
常用模块: 一个python文件就是一个模块 1.标准模块,python自带的 2.第三方模块,需要安装 3.自己写的python文件 json,就是一个字符串 1.json转为字典 json_str ...