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 ...
随机推荐
- 详解Linux(centos7)下安装OpenSSL安装图文方法
OpenSSL是一个开源的ssl技术,由于我需要使用php相关功能,需要获取https的文件所以必须安装这个东西了,下面我整理了两种关于OpenSSL安装配置方法. 安装环境: 操作系统:CentO ...
- CMFCPropertyGridProperty的使用
设定初始值 CString str(_T("Button")); COleVariant cOlevariant(str); pTypeProperty->SetOrigin ...
- Mantle 与Injection
本来Injection可以本地打补丁实时修改代码,但是不知道Mantle的数据类为何不能打补丁,可能因为Mantle利用了很多运行时的技术吧.
- 2018-2019-2 网络对抗技术 20165324 Exp2: 后门原理与实践
2018-2019-2 网络对抗技术 20165324 Exp2: 后门原理与实践 课程学习: 后门 后门:是不经过正常认证流程而访问系统的通道,存在与编译器.操作系统.固件和应用中等等. 后门工作流 ...
- 使用JDBC+POI把Excel中的数据导出到MySQL
POI是Apache的一套读MS文档的API,用它还是可以比较方便的读取Office文档的.目前支持Word,Excel,PowerPoint生成的文档,还有Visio和Publisher的. htt ...
- 论文笔记:2018 PRCV 顶会顶刊墙展
Global Gated Mixture of Second-order Pooling for Imporving Deep Convolutional Neural Network(2018 NI ...
- eclipse启动 报错,错误信息为 return exit code=13
打不开的报错如下图: 解决方法:手工配置Eclipse使用的JDK,在Eclipse的安装目录中找到eclipse.ini文件,增加正确的JDK安装目录,如图 在plugins/ 下一行,增加 -vm ...
- 如何用有NFC功能的手机微信给公交卡充值?入口在那里?
如何用有NFC功能的手机微信给公交卡充值?入口在那里? 需要两个前提: 1.NFC功能手机授权同意微信获取权限. 2.打开微信,并把公交卡放在手机背面贴紧. 选择下方的[充值金额],可以是10元.20 ...
- 精力管理 | 迅速恢复精力的N个技巧,四个关键词以及自我管理的方法和工具列表
精力管理 | 迅速恢复精力的N个技巧,所谓坚持,是坚定的“持有”,这个“持”字很值得琢磨——不是扛.不是顶,而是“持”这样一个半放松的状态.如果你没做好自己该做的事情,如果你自己没有成长起来,随着年龄 ...
- nohup 命令(设置后台进程): appending output to ‘nohup.out’ 问题
一.Linux 下使用 nohup Unix/Linux下一般比如想让某个程序在后台运行,很多都是使用 & 在程序结尾来让程序自动运行. 比如我们要运行weblogic在后台:./startW ...