【欧拉函数】BZOJ2190-[SDOI2012]longge的数学问题
【题目大意】
求出∑gcd(i, N)(1<=i <=N)。
【思路】
对于x=ak,y=bk,若gcd(a,b)=1则必有gcd(x,y)=1。枚举N的所有因数,∑gcd(i, N)=∑(φ(N/k)*k)(k|N)。
*N的因数与必须在n^(1/2)时间内求出,否则会TLE。
【代码】
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
/*注意数据范围*/
const int MAXN=;
ll n;
ll factor[MAXN]; void get_factor()
/*必须在n^(1/2)时间以内求出所有的质因数,否则会TE*/
{
memset(factor,,sizeof(factor));
ll i;
for (i=;i*i<n;i++)
{
if (n%i==)
{
factor[++factor[]]=i;
factor[++factor[]]=n/i;
}
}
if (i*i==n) factor[++factor[]]=i;
} ll eular(ll k)
{
ll res=k;
for (ll p=;p*p<=k;p++)
{
if (k%p==)
{
res=res-res/p;
while (k%p==) k/=p;
}
}
if (k>) res=res-res/k;
/*主意k可能大于0,必须要再减去*/
return res;
} void init()
{
scanf("%d",&n);
} ll get_ans()
{
ll result=;
for (ll i=;i<=factor[];i++)
result+=eular(n/factor[i])*factor[i];
return result;
} int main()
{
init();
get_factor();
cout<<get_ans()<<endl;
return ;
}
【欧拉函数】BZOJ2190-[SDOI2012]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][ ...
- 【bzoj2705】[SDOI2012]Longge的问题 欧拉函数
题目描述 Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). 输入 一个整数,为N. 输出 ...
- 【SDOI2012】Longge 的问题 题解(欧拉函数)
前言:还算比较简单的数学题,我这种数学蒟蒻也会做QAQ. --------------- 题意:求$\sum\limits_{i=1}^n gcd(i,n)$的值. 设$gcd(i,n)=d$,即$d ...
- BZOJ2705: [SDOI2012]Longge的问题(欧拉函数)
题意 题目链接 Sol 开始用反演推发现不会求\(\mu(k)\)慌的一批 退了两步发现只要求个欧拉函数就行了 \(ans = \sum_{d | n} d \phi(\frac{n}{d})\) 理 ...
- 由 [SDOI2012]Longge的问题 探讨欧拉函数和莫比乌斯函数的一些性质和关联
本题题解 题目传送门:https://www.luogu.org/problem/P2303 给定一个整数\(n\),求 \[ \sum_{i=1}^n \gcd(n,i) \] 蒟蒻随便yy了一下搞 ...
- [SDOI2012] Longge的问题 - 欧拉函数
求 \(\sum\limits_{i=1}^{n}gcd(i,n)\) Solution 化简为 \(\sum\limits_{i|n}^{n}φ(\dfrac{n}{i})i\) 筛出欧拉函数暴力求 ...
- Longge's problem poj2480 欧拉函数,gcd
Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6918 Accepted: 2234 ...
- Longge's problem(欧拉函数应用)
Description Longge is good at mathematics and he likes to think about hard mathematical problems whi ...
随机推荐
- TCP ------ TCP四次挥手(断开连接)及断开过程
1.正常情况下,调用close(),产生的其中一个效果就是发送FIN,只有双方都调用close(),才会出现正常的四次挥手. 2.如果是服务器,发起四次挥手是在关闭accept()返回的套接字,而不是 ...
- elemetUi 组件--el-upload
[需求]实现上传Excel文件,在上传到服务器时,还要附加一个参数,在请求上传文件接口前,先要进行文件格式判断. [知识点] 1.el-upload 官方文档中,主要用到了以下属性: data 可选参 ...
- DP---背包问题
http://www.hawstein.com/posts/dp-knapsack.html http://www.cnblogs.com/wwwjieo0/archive/2013/04/01/29 ...
- 【Foreign】哈密顿回路 [MIM]
哈密顿回路 Time Limit: 15 Sec Memory Limit: 256 MB Description Input Output Sample Input 4 10 0 3 2 1 3 ...
- python基础代码(猜年龄、从最内层跳出多层循环、简单的购物车程序)
1.猜年龄 , 可以让用户最多猜三次! age = 55 i=0 while i<3: user_guess = int (input ("input your guess:" ...
- linux基础——文件的压缩解压缩以及vim编辑
一.将用户信息数据库文件和组信息数据库文件纵向合并为一个文件/1.txt(覆盖) cat /etc/{passwd,group} > /1.txt 查看:cat /1.txt 二. ...
- Golang使用amqp发送消息
1.为什么使用信道(channel)而不使用TCP连接发送AMQP命令? 对操作系统来说频繁的建立和销毁TCP连接开销非常昂贵,而操作系统每秒建立的连接是有上限的,性能瓶颈不可避免,而只建立一条TCP ...
- libssh2
http://www.cnblogs.com/lzrabbit/p/4298794.html shell脚本实现ssh自动登录远程服务器示例: #!/usr/bin/expect spawn ssh ...
- vmware的3种网络模式
####图片以及部分内容来源:https://note.youdao.com/share/?id=236896997b6ffbaa8e0d92eacd13abbf&type=note#/ 在安 ...
- win32 listctrl控件右键菜单的实现
HMENU Menu_list,Menu_all; POINT point; HINSTANCE hInstance;//下面代码放到BOOL WINAPI DialogProc下 case WM_C ...