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. SVN无法Cleanup

    错误如下: 原因:svn提交遇到恶心的问题,可能是因为上次cleanup中断后,进入死循环了 解决方法:清空svn的队列 1.下载Sqlite3.exe 2.找到你项目的.svn文件,查看是否存在wc ...

  2. Jquery Easy UI Datagrid 上下移动批量保存数据

    DataGrid with 上下移动批量保存数据 通过前端变量保存修改数据集合,一次性提交后台执行 本想结合easyui 自带的$('#dg').datagrid('getChanges'); 方法来 ...

  3. SqlHelper简单实现(通过Expression和反射)10.使用方式

    以下是整个SqlHelper的Demo: public Result<List<ArticleDTO>> GetIndexArticleList(int count, int ...

  4. Java HashMap详细介绍和使用示例

    ①对HashMap的整体认识 HashMap是一个散列表,它存储的内容是键值对(key-value)映射. HashMap继承于AbstractMap,实现了Map.Cloneable.java.io ...

  5. Linux 磁盘

    一台物理服务器通常有好几块磁盘(/dev/sda,/dev/sdb),每个磁盘上都可以进行分区(例如对sda进行分区操作:fdisk /dev/sda,可以将sda分成sda1,sda2,sda5等分 ...

  6. 【c++ primer, 5e】参数传递

    p187~p199: [传值参数] [传引用参数] 使用引用形参返回额外信息:传入一个(或者多个)额外的引用实参,令其保存字符出现的次数. 6.11 #include <iostream> ...

  7. 学号20145322 《Java程序设计》第一周学习总结

    学号20145322 <Java程序设计>第一周学习总结 教材学习内容总结 Java诞生于Sun公司,于1998年12月4日发布J2SE,约以两年为一周期推出重大版本更新. 2010年Or ...

  8. let与const心智模型

    let 与 const 心智模型: let与const分别是变量与常量的块级声明关键字: 其主要目的是为了约束开发者编写出逻辑更加清晰,阅读性更好的代码: 它们体现了JavaScript的" ...

  9. 机器学习:让我们彻底搞懂CNN【转】

    本文转载自:http://115.com/182920/T1266078.html 机器学习:让我们彻底搞懂CNN 上世纪科学家们发现了几个视觉神经特点,视神经具有局部感受眼,一整张图的识别由多个局部 ...

  10. Centos为mysql开启binlog

    1.查询mysql配置文件所在位置 2.编辑配置文件/etc/my.cnf 在文件尾部添加: log-bin=/var/lib/mysql/mysql-bin server-id=123454  (5 ...