【题目大意】

求出∑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的数学问题的更多相关文章

  1. BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 2553  Solved: 1565[Submit][ ...

  2. Bzoj 2705: [SDOI2012]Longge的问题 欧拉函数,数论

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 1959  Solved: 1229[Submit][ ...

  3. 【bzoj2705】[SDOI2012]Longge的问题 欧拉函数

    题目描述 Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). 输入 一个整数,为N. 输出 ...

  4. 【SDOI2012】Longge 的问题 题解(欧拉函数)

    前言:还算比较简单的数学题,我这种数学蒟蒻也会做QAQ. --------------- 题意:求$\sum\limits_{i=1}^n gcd(i,n)$的值. 设$gcd(i,n)=d$,即$d ...

  5. BZOJ2705: [SDOI2012]Longge的问题(欧拉函数)

    题意 题目链接 Sol 开始用反演推发现不会求\(\mu(k)\)慌的一批 退了两步发现只要求个欧拉函数就行了 \(ans = \sum_{d | n} d \phi(\frac{n}{d})\) 理 ...

  6. 由 [SDOI2012]Longge的问题 探讨欧拉函数和莫比乌斯函数的一些性质和关联

    本题题解 题目传送门:https://www.luogu.org/problem/P2303 给定一个整数\(n\),求 \[ \sum_{i=1}^n \gcd(n,i) \] 蒟蒻随便yy了一下搞 ...

  7. [SDOI2012] Longge的问题 - 欧拉函数

    求 \(\sum\limits_{i=1}^{n}gcd(i,n)\) Solution 化简为 \(\sum\limits_{i|n}^{n}φ(\dfrac{n}{i})i\) 筛出欧拉函数暴力求 ...

  8. Longge's problem poj2480 欧拉函数,gcd

    Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6918   Accepted: 2234 ...

  9. Longge's problem(欧拉函数应用)

    Description Longge is good at mathematics and he likes to think about hard mathematical problems whi ...

随机推荐

  1. Codeforces Round #328 (Div. 2) A

    A. PawnChess time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  2. BZOJ1202:狡猾的商人(带权并查集)

    1202: [HNOI2005]狡猾的商人 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1202 Description: 刁姹接到一个 ...

  3. TCP ------ TCP创建服务器中出现的套接字

    在服务器端,socket()返回的套接字用于监听(listen)和接受(accept)客户端的连接请求.这个套接字不能用于与客户端之间发送和接收数据. accept()接受一个客户端的连接请求,并返回 ...

  4. sysctl -P net.bridge.bridge-nf-call-ip6tables报错解决办法

    问题症状 修改 linux 内核文件 #vi /etc/sysctl.conf后执行sysctl  -P 报错 error: "net.bridge.bridge-nf-call-ip6ta ...

  5. Active Directory Domain Services in Windows Server 2016/2012

    Applies To: Windows Server 2016, Windows Server 2012 R2, Windows Server 2012 You will find links to ...

  6. webpack 小记

    零.入口与输出 //对像语法 entry: { aa: __dirname + '/src/aa.js',    //(chunkName :path) bb: __dirname + '/src/b ...

  7. oracle11g 使用数据泵导出导入数据

    终于搞定了 快写个笔记 记录下. 删除用户的时候提示已经登录了不能删除,这个需要把登录的session结束掉. select username,sid,serial# from v$session w ...

  8. 为什么 Java中1000==1000为false而100==100为true?AND "2+2=5"?

    前提:我们知道,如果两个引用指向同一个对象,用==表示它们是相等的.如果两个引用指向不同的对象,用==表示它们是不相等的,即使它们的内容相同. 运行下面代码:

  9. 转:java 帐号激活与忘记密码 实例

    原文链接:http://endual.iteye.com/blog/1613679 一.帐户激活   在 很多时候,在某些网站注册一个用户之后,网站会给这个用户注册时填写的email地址发送一封帐户激 ...

  10. 转:Spring AOP 注解方式实现的一些“坑”

    使用过Spring AOP的注解方式实现,也入过不少坑,现在做一下记录,希望有同样需求的朋友可以少走弯路 使用之前还是先过一下官方文档吧,至少可以少走弯路,不用担心英文读不懂,其实只看代码例子就能理解 ...