【POJ】2480 Longge's problem(欧拉函数)
题目
传送门:QWQ
分析
题意就是求∑gcd(i, N) 1<=i <=N.。
显然$ gcd(i,n) = x $时,必然$x|n$。
所以我们枚举一下n的约数,对于每个约数x,显然$ gcd(i/x,n/x)=1$
所以我们计算一下n/x的欧拉函数就ok了。
联赛前刷水题qwq
代码
// #include <bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = ;
ll a[maxn], top=, p[maxn];
int fac(ll x) {
int n=x, flag=;
ll end = sqrt(x);
for(ll i=;i<=end;i++) {
if(x%i==) {
flag=;
a[++top] = i;
if(i*i!=x) a[++top] = x/i;
while(n%i==) n/=i;
}
}
if(x==) flag=;
return flag;
}
ll phi(ll x) {
ll ans = x, end = sqrt(x)+;
for(ll i=;i<=end;i++) {
if(x%i==) {
ans = ans / i * (i-);
while(x%i==) x/=i;
}
}
if(x>) ans = ans / x * (x-);
return ans;
}
void Ph() {
for(int i=;i<maxn-;i++) p[i]=i;
for(ll i=;i<maxn-;i++) {
if(p[i]==i) {
for(ll j=i;j<maxn-;j+=i) {
p[j] = p[j] / i * (i-);
}
}
}
}
int main() {
int n; Ph(); while(scanf("%lld",&n)==) {
if(n==){
printf("1\n"); continue;
}
top=; int q=fac(n);
if(q == ) {
printf("%lld\n",phi(n)+n); continue;
}
sort(a+,a++top);
int pp = top;
ll ans=phi(n)+n;
for(int i=;i<=pp;i++) {
ll qwq;
if(n/a[i] < maxn-) qwq = p[n/a[i]];
else qwq = phi(n/a[i]);
ans += a[i] * qwq;
}
printf("%lld\n",ans);
}
}
【POJ】2480 Longge's problem(欧拉函数)的更多相关文章
- poj 2480 Longge's problem [ 欧拉函数 ]
传送门 Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7327 Accepted: 2 ...
- 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 ...
- poj 2480 Longge's problem 欧拉函数+素数打表
Longge's problem Description Longge is good at mathematics and he likes to think about hard mathem ...
- poj 2480 Longge's problem 积性函数
思路:首先给出几个结论: 1.gcd(a,b)是积性函数: 2.积性函数的和仍然是积性函数: 3.phi(a^b)=a^b-a^(b-1); 记 f(n)=∑gcd(i,n),n=p1^e1*p2^e ...
- 题解报告:poj 2480 Longge's problem(欧拉函数)
Description Longge is good at mathematics and he likes to think about hard mathematical problems whi ...
- POJ 2480 Longge's problem (积性函数,欧拉函数)
题意:求∑gcd(i,n),1<=i<=n思路:f(n)=∑gcd(i,n),1<=i<=n可以知道,其实f(n)=sum(p*φ(n/p)),其中p是n的因子.为什么呢?原因 ...
- poj 3090 && poj 2478(法雷级数,欧拉函数)
http://poj.org/problem?id=3090 法雷级数 法雷级数的递推公式非常easy:f[1] = 2; f[i] = f[i-1]+phi[i]. 该题是法雷级数的变形吧,答案是2 ...
- BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 2553 Solved: 1565[Submit][ ...
- POJ 2478 Farey Sequence(欧拉函数前n项和)
A - Farey Sequence Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- Bzoj 2705: [SDOI2012]Longge的问题 欧拉函数,数论
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 1959 Solved: 1229[Submit][ ...
随机推荐
- grafana设置Alert阈值和邮件报警
首先我们需要在机器上开启smtp/25服务,这里有一个坑,注意,云主机为了防止滥发邮件已经封掉了smtp的所有通信,所以云主机发邮件是有问题的. 安装sendmail,ubuntu用apt,cento ...
- file.replace
一.简介 salt file.replace 文件内容处理函数,类似于ansible的lineinfile模块 二.参数介绍 name 被编辑文件的绝对路径,支持软链接 pattern 常规表达式,使 ...
- 对magento MVC框架的了解
对magento MVC框架的了解 在做二次开发以来,一直没有好好地去了解magento的MVC架构,以为跟其它的MVC架构一样,其实有着很大的区别. 有很多的程序框架都使用了现在最流行的MVC架构, ...
- HDU1212 大数膜
大数MOD #include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm& ...
- 2018-2019-2 网络对抗技术 20165212 Exp4 恶意代码分析
2018-2019-2 网络对抗技术 20165212 Exp4 恶意代码分析 原理与实践说明 1.实践目标 监控你自己系统的运行状态,看有没有可疑的程序在运行. 分析一个恶意软件,就分析Exp2或E ...
- 基于点线特征的Kinect2实时环境重建(Tracking and Mapping)
前言 个人理解错误的地方还请不吝赐教,转载请标明出处,内容如有改动更新,请看原博:http://www.cnblogs.com/hitcm/ 如有任何问题,feel free to contact m ...
- 不缓存AJAX
最好的办法是:写上这段代码 $.ajaxSetup({cache:false}); 这样页面中,所有的ajax请求,都执行这个,就不必改已经完成的N个接口 最初接受的办法是:在url后面添加当前时间 ...
- 使用rewrite 让php 实现类似asp.net 的IHttpModule 进行带参数js文件的参数获取
asp.net 的IHttpModule 接口具有很大的作用,我们可以使用实现的模块进行全局的控制,但是在学习php 的过程中也想实现类似的功能,查找php 的文档,自己没有找到, 但是我们大家应该知 ...
- Java8 lam。。。表达式
双冒号:相当于用了别人实现的方法,格式,类名::方法 Math::max等效于(a, b)->Math.max(a, b)String::startWith等效于(s1, s2)->s1. ...
- PHP安全相关的配置(2)
php用越来越多!安全问题更为重要!这里讲解如果安全配置php.ini 安全配置一 (1) 打开php的安全模式 php的安全模式是个非常重要的内嵌的安全机制,能够控制一些php中的函数,比如syst ...