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 ...
随机推荐
- Validate Binary Search Tree 解答
Question Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is d ...
- hdu 2438 Turn the corner(几何+三分)
Problem Description Mr. West bought a new car! So he is travelling around the city. One day he comes ...
- 查看Java包源码
- 【极客学院出品】Cocos2d-X系列课程之九-BOX2D物理引擎
Cocos2d-x 是时下最热门的手游引擎,在国内和国外手机游戏开发使用的份额各自是70%和25%,在App Store的top10中,有7个是用它开发的. 本节课程为Cocos2d-x系列课程之九, ...
- Android窗口管理服务WindowManagerService的简要介绍和学习计划
在前一个系列文章中,我们从个体的角度来分析了Android应用程序窗口的实现框架.事实上,如果我们从整体的角度来看,Android应用程序窗口的 实现要更复杂,因为它们的类型和作用不同,且会相互影响. ...
- 跟我一起学extjs5(18--模块的新增、改动、删除操作)
跟我一起学extjs5(18--模块的新增.改动.删除操作) 上节在Grid展示时做了一个金额单位能够手工选择的功能,假设你要增加其它功能.也仅仅要依照这个模式来操作即可了,比方说你想 ...
- hdu1106 字符串水题strtok()&&strchr()&&sscanf()+atoi()使用
字符串的题目 用库函数往往能大大简化代码量 以hdu1106为例 函数介绍 strtok() 原型: char *strtok(char s[], const char *delim); 功能: 分解 ...
- React-Native获取文本框的值
要想获取文本框的值,首先我们需要看一下官方文档的解释: 这里的意思是说当文本框的内容改变的时候,文本框的输入的内容就会作为一个参数进行传递.因此我们就可以获取到文本框里面的内容就好了. constru ...
- js下拉菜单默认值为当前年份,下拉菜单的选项为当前年份往前推5年
1:在jsp或者HTML页面中新建一个下拉框 年度:<select id="cx_nd" name="cx_nd" style="width: ...
- Convert Sorted List to Binary Search Tree java
public TreeNode sortedListToBST(ListNode head) { if(head==null) return new TreeNode(0); ArrayList< ...