poj 2480 Longge's problem 欧拉函数+素数打表
Description
"Oh, I know, I know!" Longge shouts! But do you know? Please solve it.
Input
A number N per line.
Output
Sample Input
2
6
Sample Output
3
15
Source
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll __int64
#define mod 1000000007
#define inf 999999999
//#pragma comment(linker, "/STACK:102400000,102400000")
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
#define MAXN 100001
ll prime[MAXN];//保存素数
ll vis[MAXN],ji;//初始化
ll Prime(ll n)
{
ll cnt=;
//memset(vis,0,sizeof(vis));
for(ll i=;i<=n;i++)
{
if(!vis[i])
prime[cnt++]=i;
for(ll j=;j<cnt&&i*prime[j]<n;j++)
{
vis[i*prime[j]]=;
if(i%prime[j]==)//关键
break;
}
}
return cnt;
}
ll phi(ll n)
{
ll i,rea=n;
for(i=;i<ji;i++)
{
if(prime[i]*prime[i]>n)break;
if(n%prime[i]==)
{
rea=rea-rea/prime[i];
while(n%prime[i]==) n/=prime[i];
}
}
if(n>)
rea=rea-rea/n;
return rea;
}
int main()
{
ll x,y,z,i,t;
ji=Prime();
while(~scanf("%I64d",&x))
{
ll ans=;
for(i=;i*i<=x;i++)
{
if(x%i==)
{
ll gg=i;
ll hh=x/i;
ans+=gg*phi(hh);
if(hh!=gg)
ans+=hh*phi(gg);
}
}
printf("%I64d\n",ans);
}
return ;
}
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 积性函数
思路:首先给出几个结论: 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 ...
- Poj 2478-Farey Sequence 欧拉函数,素数,线性筛
Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14291 Accepted: 5647 D ...
随机推荐
- [vue]vue v-on事件绑定(原生修饰符+vue自带事件修饰符)
preventDefault阻止默认行为和stopPropagation终止传递 event.preventDefault() 链接本来点了可以跳转, 如果注册preventDefault事件,则点了 ...
- [django]模板template原理
django 中的render和render_to_response()和locals(): http://www.cnblogs.com/wangchaowei/p/6750512.html 什么是 ...
- 实习培训——Java基础(3)
实习培训——Java基础(3) 1 Java 继承 1.1 super和this关键字 super关键字:我们可以通过super关键字来实现对父类成员的访问,用来引用当前对象的父类. this关键字 ...
- 全文搜索引擎Xapian
安装过程 安装xapian-core wget http://oligarchy.co.uk/xapian/1.0.13/xapian-core-1.0.13.tar.gztar zxvf xapia ...
- c#中WMI 中的日期和时间转为本地时间
取得的值:CreationDate:20170122084915 .713600+480 转: var objQuery = new ObjectQuery("select * from ...
- ExtJs中XTemplate使用(转)
转自http://www.studyofnet.com/news/408.html 本文导读:XTemplate是Ext.Template扩展的新类,它支持高级功能的模板类,如自动数组输出.条件判断. ...
- java常用功能
1.复制文件 private void fileChannelCopy(File source, File target) throws IOException { FileInputStream f ...
- bzoj3196: Tyvj 1730 二逼平衡树 树套树
地址:http://www.lydsy.com/JudgeOnline/problem.php?id=3196 题目: 3196: Tyvj 1730 二逼平衡树 Time Limit: 10 Sec ...
- Postman: Pre-request Script,设置body 变量
1)Postman Pre-request Script 设置变量名 2)把变量放在body里 3)Send后查看变量是否被替换
- 20165207 Exp1 PC平台逆向破解
20165207 Exp1 PC平台逆向破解 0.写在最前面 在做三个实验的前两个的时候,我还没有到博客里去看作业的要求.当时我的主机名是kali5207也就是用我的学号命名的,要求的是姓名全拼命名k ...