poj2480-Longge's problem-(欧拉函数)
"Oh, I know, I know!" Longge shouts! But do you know? Please solve it.
Input
A number N per line.
Output
Sample Input
2
6
Sample Output
3
15
翻译:给一个数n,1<=i<=n,求gcd(i,n)之和。
解题过程:
令d=gcd(i,n),d必然是n的因子,并且是i和n的最大公因子。
则gcd(i/d,n/d)=1。令y=n/d,通过y求出与y互质的数的个数,然后对这个数量乘以最大公因子d,累加。
#include <iostream>
#include<stdio.h>
#include <algorithm>
#include<string.h>
#include<cstring>
#include<math.h>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std; ll euler(ll x)
{
ll res=x;
for(ll i=;i*i<=x;i++)
{
if(x%i==)
{
res=res/i*(i-);
while(x%i==)
x=x/i;
}
}
if(x>)
res=res/x*(x-);
return res;
} int main()
{
ll n,sum;
while(scanf("%lld",&n)!=EOF)
{
sum=;
ll i;
for(i=;i*i<=n;i++)
{
if(n%i==)
sum+=i*euler(n/i)+(n/i)*euler(i);
}
i--;
if(i*i==n)
sum-=i*euler(i);
printf("%lld\n",sum);
}
return ;
}
poj2480-Longge's problem-(欧拉函数)的更多相关文章
- poj 2480 Longge's problem [ 欧拉函数 ]
传送门 Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7327 Accepted: 2 ...
- POJ 2480 Longge's problem 欧拉函数—————∑gcd(i, N) 1<=i <=N
Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6383 Accepted: 2043 ...
- poj 2480 Longge's problem 欧拉函数+素数打表
Longge's problem Description Longge is good at mathematics and he likes to think about hard mathem ...
- BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 2553 Solved: 1565[Submit][ ...
- Bzoj 2705: [SDOI2012]Longge的问题 欧拉函数,数论
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 1959 Solved: 1229[Submit][ ...
- 【bzoj2705】[SDOI2012]Longge的问题 欧拉函数
题目描述 Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). 输入 一个整数,为N. 输出 ...
- BZOJ2705: [SDOI2012]Longge的问题(欧拉函数)
题意 题目链接 Sol 开始用反演推发现不会求\(\mu(k)\)慌的一批 退了两步发现只要求个欧拉函数就行了 \(ans = \sum_{d | n} d \phi(\frac{n}{d})\) 理 ...
- [SDOI2012] Longge的问题 - 欧拉函数
求 \(\sum\limits_{i=1}^{n}gcd(i,n)\) Solution 化简为 \(\sum\limits_{i|n}^{n}φ(\dfrac{n}{i})i\) 筛出欧拉函数暴力求 ...
- UVa 10837 A Research Problem 欧拉函数
题意: 给你一个欧拉函数值 phi(n),问最小的n是多少. phi(n) <= 100000000 , n <= 200000000 解题思路: 对于欧拉函数值可以写成 这里的k有可能是 ...
- Bzoj-2705 Longge的问题 欧拉函数
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2705 题意: 求 sigma(gcd(i,n), 1<=i<=n<2^3 ...
随机推荐
- 小朋友学C语言(2):安装Dev C++编译器
(一)编译器 编译器是将“一种语言(通常为高级语言)”翻译为“另一种语言(通常为低级语言)”的程序.一个现代编译器的主要工作流程:源代码 (source code) -->预处理器 (prepr ...
- 《linux性能及调优指南》 3.3 内存瓶颈
摘要:3.3内存瓶颈OnaLinuxsystem,manyprogramsrunatthesametime.Theseprogramssupportmultipleusers,andsomeproce ...
- c#linq去除重复项并将相同数据的数量字段值相加
这是执行前和执行后想要的效果 以下是用Sql语句实现的代码: select goodsno, goodsspec,SUM([count]) as count from goods group by g ...
- QQ号码正则判断
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- jQuery插件——下拉选择框
其实,之前也写过jQuery插件,今天写的是一个模拟select选择的下拉插件. 既然是jQuery插件,那么必然是依赖jQuery的了. 老规矩,直接上代码吧! ;(function () { $. ...
- nodejs基础学习1
ES6常用新语法 ES6新语法 什么是ES6? 由于JavaScript是上个世纪90年代,由Brendan Eich在用了10天左右的时间发明的:虽然语言的设计者很牛逼,但是也扛不住"时间 ...
- 8.代理ip使用
我日常常用的两个代理: 一.风讯代理 http://www.gzkangyun.com/ 操作界面: 二.智连代理 综合感觉吧,还是智连好用一点,ip质量相对好一点,价格也便宜,不过一个ip基本上的存 ...
- java中的排序--排序容器_TreeSet与TreeMap
1.TreeSet:数据元素可以排序且不可重复. 对比: (1)Set接口:HashSet,元素必须重写hashcode和equals方法. (2)TreeSet:只要可以排序即可.去重:比较等于0即 ...
- aptana studio 使用技巧整理
aptana studio 使用技巧整理 https://192.168.1.16/web/punica/adaptana studio 使用技巧整理http://uedfans.cn/ 推荐一个网站 ...
- Centos7 用户登录失败N次后锁定用户禁止登陆
参考网站:https://blog.csdn.net/qq_33285112/article/details/78813369 未试 思路是查找/var/log/secure中验证失败且出现的次数较 ...