GCD

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
 
描述
The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),is the largest divisor common to a and b,For example,(1,2)=1,(12,18)=6.
(a,b) can be easily found by the Euclidean algorithm. Now Carp is considering a little more difficult problem:
Given integers N and M,please answer sum of  X satisfies 1<=X<=N and (X,N)>=M.
 
输入
The first line of input is an integer T(T<=100) representing the number of test cases. The following T lines each contains two numbers N and M (1<=N<=10^9, 1<=M<=10^9), representing a test case.
输出
Output the answer mod 1000000007
样例输入
3
1 1
10 2
10000 72
样例输出
1
35
1305000
上传者
ACM_张书军
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = ;
const int moder = ; ll eular(ll n)
{
ll ans = n;
for(int i=;i*i <= n;i++){
if(n%i == ){
ans = ans - ans/i;
while(n%i == )
n = n/i;
}
}
if(n > )
ans = ans - ans/n;
return ans;
} ll eular_sum(ll k)
{
if(k==||k==)
return ;
else return k*eular(k)/;
} int main()
{
int t;
scanf("%d",&t);
while(t--){
ll n,m;
scanf("%lld%lld",&n,&m);
ll res = ;
for(int i=;i*i <= n;i++) {
if (n % i == ) {
if (i >= m) {
res = (res + i * eular_sum(n / i))%moder;
}
if (i * i != n && n / i >= m){
res = (res + n/i*eular_sum(i))%moder;
}
}
}
printf("%lld\n",res);
}
return ;
}

//求欧拉函数(即n以内所有与n互质的数的个数)

// 设n的质因数分别为p1,p2,.....,pn

//f(x)=n*(1-p1)*(1-p2)*...*(1-pn)

//求与n互质的数之和S(x)=f(x)/2*x

nyoj1007——欧拉求和的更多相关文章

  1. poj3090欧拉函数求和

    E - (例题)欧拉函数求和 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     ...

  2. 【BZOJ4805】欧拉函数求和(杜教筛)

    [BZOJ4805]欧拉函数求和(杜教筛) 题面 BZOJ 题解 好久没写过了 正好看见了顺手切一下 令\[S(n)=\sum_{i=1}^n\varphi(i)\] 设存在的某个积性函数\(g(x) ...

  3. BZOJ4805: 欧拉函数求和(杜教筛)

    4805: 欧拉函数求和 Time Limit: 15 Sec  Memory Limit: 256 MBSubmit: 614  Solved: 342[Submit][Status][Discus ...

  4. HDU2824-The Euler function-筛选法求欧拉函数+求和

    欧拉函数: φ(n)=n*(1-1/p1)(1-1/p2)....(1-1/pk),其中p1.p2-pk为n的所有素因子.比如:φ(12)=12*(1-1/2)(1-1/3)=4.可以用类似求素数的筛 ...

  5. [BZOJ]4805: 欧拉函数求和

    解题思路类似莫比乌斯函数之和 题目大意:求[1,n]内的欧拉函数$\varphi$之和.($n<=2*10^{9}$) 思路:令$ M(n)=\sum_{i=1}^{n}\varphi (i)  ...

  6. hdu2421-Deciphering Password-(欧拉筛+唯一分解定理+积性函数+立方求和公式)

    Deciphering Password Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  7. 【bzoj3944/bzoj4805】Sum/欧拉函数求和 杜教筛

    bzoj3944 题目描述 输入 一共T+1行 第1行为数据组数T(T<=10) 第2~T+1行每行一个非负整数N,代表一组询问 输出 一共T行,每行两个用空格分隔的数ans1,ans2 样例输 ...

  8. 【POJ 2480】Longge's problem(欧拉函数)

    题意 求$ \sum_{i=1}^n gcd(i,n) $ 给定 $n(1\le n\le 2^{32}) $. 链接 题解 欧拉函数 $φ(x)$ :1到x-1有几个和x互质的数. gcd(i,n) ...

  9. Bi-shoe and Phi-shoe(欧拉函数)

    题意: 给一些数Ai(第 i 个数),Ai这些数代表的是某个数欧拉函数的值,我们要求出数 Ni 的欧拉函数值不小于Ai.而我们要求的就是这些 Ni 这些数字的和sum,而且我们想要sum最小,求出su ...

随机推荐

  1. Python(面向对象5——高级)

    面向对象进阶 一 isinstance(obj,cls)和issubclass(sub,super) isinstance(obj,cls)检查是否obj是否是类 cls 的对象 1 class Fo ...

  2. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E Underground Lab

    地址:http://codeforces.com/contest/782/problem/E 题目: E. Underground Lab time limit per test 1 second m ...

  3. Python之路——线程池

    1 线程基础 1.1 线程状态 线程有5种状态,状态转换的过程如下图所示: 1.2 线程同步——锁 多线程的优势在于可以同时运行多个任务(至少感觉起来是这样,其实Python中是伪多线程).但是当线程 ...

  4. JMS API(二)

    JMS 公共API 接口共7个: 1.ConnectionFactory 2.Destination 3.Connection 4.Session 5.Message 6.MessageProduce ...

  5. springCloud4---feign

    JAX-WS : soap是遵循这个标准. JAX-RS : 标准,jersey框架遵循这个标准. Feign是一个声明式的web service客户端.Feign使用的负载均衡也是ribbon,Fe ...

  6. Ubuntu16.04安装印象笔记

    Nixnote 是一个 Evernote 开源客户端,原名 Nevernote.Evernote 是一个著名的笔记等个人资料整理和同步软件, 因为 Evernote 没有 Linux 下的官方版本,因 ...

  7. jquery ajax修改全局变量或者局部变量示例代码

    今天在工作的时候遇见一个问题,利用ajax到action中查询返回的值付给全局变量或者局部变量,总是改变不了,后来查找资料才发现需要添加async:false 示例代码: var status=1; ...

  8. 运行bat时隐藏cmd窗口

    运行bat时隐藏cmd窗口 新建一个shrjj.vbs文件,文件内容为: Set ws = CreateObject("Wscript.Shell") ws.run "c ...

  9. oracle错误一览表

    ORA-00001: 违反唯一约束条件 (.)ORA-00017: 请求会话以设置跟踪事件ORA-00018: 超出最大会话数ORA-00019: 超出最大会话许可数ORA-00020: 超出最大进程 ...

  10. 如何用纯 CSS 创作单元素点阵 loader

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览.https://codepen.io/comehope/pen/YvBvBr 可交互视频 此 ...