Senior PanⅡ

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)

Problem Description

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.

 
Input
The first line contains one integer T, represents the number of Test Cases.
Then T lines, each contains three integers L,R,K(1≤L≤R≤10^11,2≤K≤10^11)
 
Output
For every Test Case, output one integer: the answer mod 10^9+7
 
Sample Input
2
1 20 5
2 6 3
 
Sample Output
Case #1: 5
Case #2: 3
 
Source

占坑;。。。其实是不想写,容斥我用莫比乌斯函数推出来的

突然发现我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素数测试+容斥的更多相关文章

  1. 2017多校第9场 HDU 6169 Senior PanⅡ 数论,DP,爆搜

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6169 题意:给了区间L,R,求[L,R]区间所有满足其最小质数因子为k的数的和. 解法: 我看了这篇b ...

  2. 数论 - Miller_Rabin素数测试 + pollard_rho算法分解质因数 ---- poj 1811 : Prime Test

    Prime Test Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 29046   Accepted: 7342 Case ...

  3. Miller_Rabin 素数测试

    费马定理的逆定理几乎可以用来判断一个数是否为素数,但是有一些数是判断不出来的,因此,Miller_Rabin测试方法对费马的测试过程做了改进,克服其存在的问题. 推理过程如下(摘自维基百科): 摘自另 ...

  4. Miller_Rabin素数测试【学习笔记】

    引语:在数论中,对于素数的研究一直就很多,素数测试的方法也是非常多,如埃式筛法,6N±1法,或者直接暴力判(试除法).但是如果要判断比较大的数是否为素数,那么传统的试除法和筛法都不再适用.所以我们需要 ...

  5. HDU 6166 Senior Pan (最短路变形)

    题目链接 Problem Description Senior Pan fails in his discrete math exam again. So he asks Master ZKC to ...

  6. HDU 6166.Senior Pan()-最短路(Dijkstra添加超源点、超汇点)+二进制划分集合 (2017 Multi-University Training Contest - Team 9 1006)

    学长好久之前讲的,本来好久好久之前就要写题解的,一直都没写,懒死_(:з」∠)_ Senior Pan Time Limit: 12000/6000 MS (Java/Others)    Memor ...

  7. HDU 6166 Senior Pan 二进制分组 + 迪杰斯特拉算法

    Senior Pan Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Probl ...

  8. HDU How many integers can you find 容斥

    How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  9. HDU - 4336:Card Collector(min-max容斥求期望)

    In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, fo ...

随机推荐

  1. 如何干净卸载mysql

    一.在控制面板中卸载mysql软件: 二.卸载过后删除C:\Program Files (x86)\MySQL该目录下剩余了所有文件,把mysql文件夹也删了: 三.windows+R运行“reged ...

  2. AtCoder Beginner Contest 085(ABCD)

    A - Already 2018 题目链接:https://abc085.contest.atcoder.jp/tasks/abc085_a Time limit : 2sec / Memory li ...

  3. [转载] Web Service工作原理及实例

    一.Web Service基本概念   Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求, ...

  4. socket.io不为人知的功能

    socket.io 是一个基于websocket实现的前后端实时通讯框架,也对低版本浏览器做了封装.使用起来简单,方便. 初次使用起来可能会比较迷糊,其实主要常用就几个方法,简单介绍一下. //客户端 ...

  5. 前端框架VUE----指令

    一.什么是VUE? 它是构建用户界面的JavaScript框架(让它自动生成js,css,html等) 二.怎么使用VUE? 1.引入vue.js 2.展示HTML <div id=" ...

  6. Inception 模型

    https://blog.csdn.net/xxiaozr/article/details/71481356 inception v1: 去除了最后的全连接层,使用全局平均池化层来代替,因为全连接层的 ...

  7. pyqt5 界面切换

    QStackedWidget 只需要关联好对应的信号和槽,调用setCurrentIndex函数,想切哪个界面就切到哪个界面

  8. Leetcode480-Sliding Window Median

    Median is the middle value in an ordered integer list. If the size of the list is even, there is no ...

  9. php中session同ip不同端口的多个网站session冲突的解决办法

    在局域网内使用IP加端口的访问方式搭了两个相同程序的站,结果发现用户在一个站下登录后,在另一个站也同时登录了,在一个退出后,另一个站也同时退出了.看了下程序发现两个站都是使用纯session方式记录登 ...

  10. P2114 [NOI2014]起床困难综合症(二进制)

    P2114 [NOI2014]起床困难综合症 我们开始设俩数,一个二进制表示全是1,另一个全是0(就是2147483647 和 0 辣) 蓝后跑一遍门 于是最后有4种情况 1->0,1-> ...