【欧拉函数】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 ...
随机推荐
- CSS垂直居中小结
1.设置子元素: { ... position :absolute; margin:auto; top:; right:; bottom:; left:; } 2.设置子元素:(height必须是固定 ...
- js页面 读身份证
硬件是 神思读卡器, 需要安装这个东西的驱动. 在web页面读取的话, 下载cab的包 进行注册, <OBJECT classid="clsid:F1317711-6BDE-4658- ...
- 金中欢乐赛 A题
题目传送门 这道题就贪心.... 正的一坨和负的一坨间隔 #include<cstdio> #include<cstring> #include<algorithm> ...
- 【BZOJ】1592: [Usaco2008 Feb]Making the Grade 路面修整
[算法]动态规划DP [题解] 题目要求不严格递增或不严格递减. 首先修改后的数字一定是原来出现过的数字,这样就可以离散化. f[i][j]表示前i个,第i个修改为第j个数字的最小代价,a表示排序后数 ...
- bzoj 1060 贪心
设根到每个叶子节点的距离为dis,比较容易的看出来,我们需要把这颗树的所有叶子节点的值都变成其中最大的内个,我们设为max,那么对于一颗子树来说,设其中dis值最大的为x,我们需要将这个子树根节点和子 ...
- Red-Black Tree
A red-black tree is a Binary Search Tree that satisfy the red-black tree properties: 1. Every node i ...
- mongoDB的文档查询
1.简单查询: find() 方法以非结构化的方式来显示所有文档. 语法 MongoDB 查询数据的语法格式如下: collection是集合名字,注意应该是当前数据库的集合,collect ...
- jqueryDateTable.js排序
{% block js %} <script type="text/javascript"> $('#datatable').dataTable( { "or ...
- pychart
Pychart PyChart is a Python library for creating high quality Encapsulated Postscript, PDF, PNG, or ...
- locust===Writing a locustfile
The Locust class A locust class represents one user (or a swarming locust if you will). Locust will ...