nyoj1007——欧拉求和
GCD
- 描述
- 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——欧拉求和的更多相关文章
- poj3090欧拉函数求和
E - (例题)欧拉函数求和 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB ...
- 【BZOJ4805】欧拉函数求和(杜教筛)
[BZOJ4805]欧拉函数求和(杜教筛) 题面 BZOJ 题解 好久没写过了 正好看见了顺手切一下 令\[S(n)=\sum_{i=1}^n\varphi(i)\] 设存在的某个积性函数\(g(x) ...
- BZOJ4805: 欧拉函数求和(杜教筛)
4805: 欧拉函数求和 Time Limit: 15 Sec Memory Limit: 256 MBSubmit: 614 Solved: 342[Submit][Status][Discus ...
- 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.可以用类似求素数的筛 ...
- [BZOJ]4805: 欧拉函数求和
解题思路类似莫比乌斯函数之和 题目大意:求[1,n]内的欧拉函数$\varphi$之和.($n<=2*10^{9}$) 思路:令$ M(n)=\sum_{i=1}^{n}\varphi (i) ...
- hdu2421-Deciphering Password-(欧拉筛+唯一分解定理+积性函数+立方求和公式)
Deciphering Password Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 【bzoj3944/bzoj4805】Sum/欧拉函数求和 杜教筛
bzoj3944 题目描述 输入 一共T+1行 第1行为数据组数T(T<=10) 第2~T+1行每行一个非负整数N,代表一组询问 输出 一共T行,每行两个用空格分隔的数ans1,ans2 样例输 ...
- 【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) ...
- Bi-shoe and Phi-shoe(欧拉函数)
题意: 给一些数Ai(第 i 个数),Ai这些数代表的是某个数欧拉函数的值,我们要求出数 Ni 的欧拉函数值不小于Ai.而我们要求的就是这些 Ni 这些数字的和sum,而且我们想要sum最小,求出su ...
随机推荐
- python16_day21【git and celery】
一.Git使用 ## GIT常用执令说明 * 初始化git项目 > git init * 查看当前目录状态 > git status * 把代码提交到stage区 > git add ...
- 磁盘结构,平均寻道时间,平均延迟时间,虚拟内存与MMU
首先了解一下磁盘:磁盘低速的原因是因为它一种机械装置,在磁盘中有一个或多个金属盘片,它们以5400,7200或10800rpm(RPM =revolutions per minute 每分钟多少转 ) ...
- Delphi程序调用C#.Net编译的DLL并打开窗体(详解)
Delphi程序调用C#.Net编译的DLL并打开窗体(详解)最近用C#.Net写了一个公用模块, 本以为仅提供给.Net程序使用, 但是领导要求把这些功能提供给旧系统使用, 天啦, 几套旧系统全是D ...
- [Windows Powershell]-学习笔记(4)
Powershell 定义变量 在powershell中变量名均是以美元符"$"开始,剩余字符可以是数字.字母.下划线的任意字符,并且powershell变量名大小写不敏感($a和 ...
- find()函数
find()函数返回类型:size_type 1/S.find(T):返回T在S中第一次匹配的下标位置 2/S.find_first_of(T):返回字符串T第一个字符在S中第一次出现的下标位置 3/ ...
- DevStore教你如何玩转饥饿营销?
首先我们必需知道: 所谓“饥饿营销”,是指商品提供者有意调低产量,以期达到调控供求关系.制造供不应求“假象”.维持商品较高售价和利润率的目的. 饥饿营销”营销方式,其通常的步骤: 1.引起关注.首先是 ...
- hdu5716
地址: 题目: 带可选字符的多字符串匹配 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- 好的博客参考之Spring
https://blog.csdn.net/bao19901210/article/details/41724355
- linux 自启动方法
参考文章:http://vod.sjtu.edu.cn/help/Article_Print.asp?ArticleID=626 http://hiandroidstudio.blog.51cto.c ...
- js 空数组 空对象判断
js 空数组是true还是false 1 2 var arr = new Array(); // 或 var arr = []; 我们知道,初始化后,即使数组arr中没有元素,也是一个object ...