hdu-5780 gcd(数学)
题目链接:
gcd
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 131072/131072 K (Java/Others)
query ∑gcd(xa−1,xb−1) (1≤a,b≤n)
For each test case ,the single line contains two integers x and n ( 1≤x,n≤1000000)
/************************************************
┆ ┏┓ ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃ ┃ ┆
┆┃ ━ ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃ ┃ ┆
┆┃ ┻ ┃ ┆
┆┗━┓ ┏━┛ ┆
┆ ┃ ┃ ┆
┆ ┃ ┗━━━┓ ┆
┆ ┃ AC代马 ┣┓┆
┆ ┃ ┏┛┆
┆ ┗┓┓┏━┳┓┏┛ ┆
┆ ┃┫┫ ┃┫┫ ┆
┆ ┗┻┛ ┗┻┛ ┆
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=1e6+10;
const int maxn=1e5+4;
const double eps=1e-8; int phi[N];
LL sum[N]; inline void Init()
{
phi[1]=1;
sum[1]=1;
For(i,2,N-1)
{
if(!phi[i])
{
for(int j=i;j<N;j+=i)
{
if(!phi[j])phi[j]=j;
phi[j]=phi[j]/i*(i-1);
}
}
sum[i]=sum[i-1]+phi[i];
}
}
LL pow_mod(LL x,int y)
{
LL s=1,base=x;
while(y)
{
if(y&1)s=s*base%mod;
base=base*base%mod;
y>>=1;
}
return s;
} int main()
{
Init();
int t,n;
LL x;
read(t);
while(t--)
{
read(x);read(n);
LL ans=0;
if(x==1)cout<<"0\n";
else
{
LL temp=pow_mod(x-1,(int)mod-2);
int l=1,r;
while(l<=n)
{
r=n/(n/l);
LL g=((pow_mod(x,r+1)-pow_mod(x,l)+mod)*temp-(r-l+1)+mod)%mod;
ans=(ans+(2*sum[n/l]-1)%mod*g)%mod;
l=r+1;
}
cout<<ans<<"\n"; } }
return 0;
}
hdu-5780 gcd(数学)的更多相关文章
- hdu 5780 gcd
题意:给定$x, n$满足$1 \leq x, n \leq 1000000$,求$\sum{(x^a-1,x^b-1)}$对$1e9+7$取模后的值,其中$1 \leq a, b \leq n$. ...
- HDU 5726 GCD 区间GCD=k的个数
GCD Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- HDU 5902 GCD is Funny 数学
GCD is Funny 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5902 Description Alex has invented a ne ...
- hdu 4497 GCD and LCM 数学
GCD and LCM Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4 ...
- HDU 5726 GCD (2016多校、二分、ST表处理区间GCD、数学)
题目链接 题意 : 给出一个有 N 个数字的整数数列.给出 Q 个问询.每次问询给出一个区间.用 ( L.R ) 表示.要你统计这个整数数列所有的子区间中有多少个和 GCD( L ~ R ) 相等.输 ...
- 数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)
先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N i ...
- 数学--数论--HDU 5223 - GCD
Describtion In mathematics, the greatest common divisor (gcd) of two or more integers, when at least ...
- 数学--数论--HDU 5382 GCD?LCM?(详细推导,不懂打我)
Describtion First we define: (1) lcm(a,b), the least common multiple of two integers a and b, is the ...
- HDU 4497 GCD and LCM (数学,质数分解)
题意:给定G,L,分别是三个数最大公因数和最小公倍数,问你能找出多少对. 析:数学题,当时就想错了,就没找出规律,思路是这样的. 首先G和L有公因数,就是G,所以就可以用L除以G,然后只要找从1-(n ...
- HDU 1695 GCD (欧拉函数+容斥原理)
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
随机推荐
- WCF TCP通信方式 通过IIS承载调试
http://www.cnblogs.com/nikymaco/archive/2012/10/08/2715954.html IIS Express服务器只支持http/https,不支持net.t ...
- 京东2015年应届生招聘笔试题(A)卷答案选择题部分
1.操作系统死锁的必要条件(多选题):() A.相互排斥条件 B.系统资源有限 C.进程调度不合理 D.环路等待条件 答:A,C,D 參考资料:http://blog.sina.com ...
- vim 穿越时空
1. 回到以前的文件状态 :earlier 3m 回到文件3分钟之前的状态 2. 回到以后的文件状态 :later 3m 回到文件3分钟之后的状态 3. 时间单位 s 秒 m 分钟 d ...
- webpack3.0 环境搭建
额.备份一下总是好的 #为了避免某些国外镜像源安装失败,先设置淘宝镜像代理 yarn config set registry https://registry.npm.taobao.org # 初始化 ...
- The Google File System论文拜读
The Google File System Sanjay Ghemawat, Howard Gobioff, and Shun-Tak Leung Google∗ 摘要 我们设计并实现了谷歌文件系统 ...
- HDU3549_Flow Problem(网络流/EK)
Flow Problem Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Tot ...
- Flyweight Design Pattern 共享元设计模式
就是利用一个类来完毕多种任务.不用每次都创建一个新类. 个人认为这个设计模式在C++里面,好像能够就使用一个函数取代,利用重复调用这个函数完毕任务和重复利用这个类,好像几乎相同. 只是既然是一个设计模 ...
- Mybatis之Mapper动态代理
一.什么是Mapper的动态代理 采用Mapper动态代理方法只需要编写相应的Mapper接口(相当于Dao接口),那么Mybatis框架根据接口定义创建接口的动态代理对象,代理对象的方法体同Dao接 ...
- linux自动ftp上传与下载文件的简单脚本
#!/bin/sh cd /data/backup/55mysql DATE=`date +'%Y%m%d'`file="55_mysql_"$DATE"03*.rar& ...
- ast.literal_eval(jsonStr) json格式字符串转dict 2种方式
json.loads(jsonStr, encoding='utf-8')import ast ast.literal_eval(jsonStr)