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. shell脚本和python脚本实现批量ping IP测试

    先建一个存放ip列表的txt文件: [root@yysslopenvpn01 ~]# cat hostip.txt 192.168.130.1 192.168.130.2 192.168.130.3 ...

  2. Oracle执行计划 explain plan

    Rowid的概念:rowid是一个伪列,既然是伪列,那么这个列就不是用户定义,而是系统自己给加上的. 对每个表都有一个rowid的伪列,但是表中并不物理存储ROWID列的值.不过你可以像使用其它列那样 ...

  3. 左移和右移运算符<< >>

    左移的符号为<< 首先来个简单的例子    求8左移两位的值  8<<2   首先 将十进制的8转为二进制的数    倒序输出----> 1000 1000  左移两位 ...

  4. apache的rewrite机制配置

    步骤: 1:启用rewrite模块,在默认情况下,没有启用 修改httpd.conf文件 #启动rewrite模块 LoadModule rewrite_module modules/mod_rewr ...

  5. mysql用户的增删与密码丢失问题

    为root用户设置初始密码 mysqladmin -u root password 密码(单实例) mysqladmin -u root password 密码 -S /data/3306/mysql ...

  6. 【ASP.Net MVC3 】使用Unity 实现依赖注入

    转载于:http://www.cnblogs.com/techborther/archive/2012/01/06/2313498.html 家人身体不太好,好几天没在园子里发帖了. 新项目还是要用M ...

  7. 通过注册表regedit对Windows回收站进行恢复

    误删资料恢复 一不小心,删错了,还把回收站清空了,咋办啊? 只要三步,你就能找回你删掉并清空回收站的东西 步骤: 1.单击"开始——运行,然后输入regedit(打开注册表) 2.依次展开: ...

  8. Codeforces 844D Interactive LowerBound - 随机化

    This is an interactive problem. You are given a sorted in increasing order singly linked list. You s ...

  9. day28 网络编程

    网络编程 什么是网络编程? 编写基于网络的应用程序的过程称之为网络编程 一.CS构架 C/S构架 服务器和客户端之间用网线连接 提供数据的计算机称为服务器,访问数据的计算机称为客户端 二.网络通讯的基 ...

  10. topcoder srm 495 div1

    problem1 link 从前向后确定一下,然后再从后向前确定一下.一样的话就是可以确定的. problem2 link 首先将强连通分量缩点.理论上来说,只需要遍历所有入度为0的联通块中的一个即可 ...