Longge的问题(欧拉,思维)
Description
Input
Output
Sample Input
6
Sample Output
15
Hint
【数据范围】
对于60%的数据,0<N<=2^16。
对于100%的数据,0<N<=2^32。
题解:题目让求∑gcd(i, N)(1<=i <=N);很显然暴力是不行的,由于gcd(m,n)=k,所以gcd(m/k,n/k)=1;要求小于等于n的最大公约数是k的个数num[k]等于ouler[n/k];枚举k求k*num[k]的和即可;
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#include<string>
using namespace std;
typedef long long LL;
LL ouler(LL n){
LL ans=n;
for(LL i=;i*i<=n;i++){
if(n%i==){
ans=ans*(i-)/i;
while(n%i==)n/=i;
}
}
if(n>)ans=ans*(n-)/n;
return ans;
}
int main(){
LL N;
while(~scanf("%lld",&N)){
LL ans=;
for(LL i=;i*i<=N;i++){
if(N%i==){
ans+=ouler(N/i)*i;
if(N/i>sqrt(1.0*N))ans+=ouler(i)*(N/i);//这里ouler[N/N/i]=ouler[i]计算最大公约数是N/i的个数
}
}
printf("%lld\n",ans);
}
return ;
}
Longge的问题(欧拉,思维)的更多相关文章
- 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][ ...
- 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 ...
- 【bzoj2705】[SDOI2012]Longge的问题 欧拉函数
题目描述 Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). 输入 一个整数,为N. 输出 ...
- poj 2480 Longge's problem [ 欧拉函数 ]
传送门 Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7327 Accepted: 2 ...
- 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\) 筛出欧拉函数暴力求 ...
- poj 2480 Longge's problem 欧拉函数+素数打表
Longge's problem Description Longge is good at mathematics and he likes to think about hard mathem ...
- Bzoj-2705 Longge的问题 欧拉函数
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2705 题意: 求 sigma(gcd(i,n), 1<=i<=n<2^3 ...
随机推荐
- UESTC_Infected Land 2015 UESTC Training for Search Algorithm & String<Problem G>
G - Infected Land Time Limit: 6000/3000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others ...
- Family Tree
Question A traditional constructing tree problem. Given a string to represent relationships, and pri ...
- 如何区分监督学习(supervised learning)和非监督学习(unsupervised learning)
监督学习:简单来说就是给定一定的训练样本(这里一定要注意,样本是既有数据,也有数据对应的结果),利用这个样本进行训练得到一个模型(可以说是一个函数),然后利用这个模型,将所有的输入映射为相应的输出,之 ...
- SDK调试出错小技巧=。=
学习Unity小伙伴完全不懂Android编程抓错误是很困难的..... 1. 使用UnityPlayer.UnitySendMessage(); 发送到Unity使用OnGUI显示错误 2. 直接在 ...
- 兼容各个浏览器的H.264播放: H.264+HTML5+FLOWPLAYER+WOWZA+RMTP
一.方案确定 计划做视频播放,要求可以播放H264编码的mp4文件,各个浏览器,各种终端都能播放. 首先查找可行性方案, http://www.cnblogs.com/sink_cup/archive ...
- MySQL搜索: WHERE 多条件
WHERE能够按多条件进行搜索. products表例如以下: a WHERE后以and 接两个条件以及三个条件进行搜索: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkb ...
- Android 之 Gallery
1 在 xml 布局中添加 Gallery activity_main.xml <LinearLayout xmlns:android="http://schemas.andro ...
- Android - 使用Intent来启动Activity
本文地址: http://blog.csdn.net/caroline_wendy/article/details/21455141 Intent 的用途是 绑定 应用程序组件, 并在应用程序之间进行 ...
- Java - 反射机制(Reflection)
Java - 反射机制(Reflection) > Reflection 是被视为 动态语言的关键,反射机制允许程序在执行期借助于 Reflection API 取得任何类的 ...
- 三、Mp3帧分析(数据帧)
一. 帧 帧头长4字节,是的,是4个字节,共32位. 帧头后面可能有两个字节的CRC 校验,这两个字节的是否存在决定于FRAMEHEADER 信息的第16bit, 为0 则帧头后面无校验,为1 则有校 ...