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 ...
随机推荐
- ConcurrentModificationException
//需求:如何集合中有给定的元素就在集合中在插入一个元素public class ListIteratorDemo2 { public static void main(String[] args) ...
- Qt QDataTime QString 两个类的使用
QDateTime now = QDateTime::currentDateTime(); QString nowStr; nowStr = now.toString("yyyyMMdd_h ...
- memcache分布式布置方案
利用hash算法 key->hash->取余%2 mod ->server=array()=>server[mod]算出是第几个memcache服务器
- html5新元素练习(1)
1, <nav> 是专门由于菜单导航,链接导航的元素 2, <header> 主体页面的头部,与head不同,它的内容可以显示出来 3, <footer>页面 ...
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) C. Maximum splitting
地址: 题目: C. Maximum splitting time limit per test 2 seconds memory limit per test 256 megabytes input ...
- chrome谷歌浏览器用这种方式清除缓存比较方便了,必须是调试模式才行
chrome谷歌浏览器用这种方式清除缓存比较方便了 PS:必须是调试模式才行,可以不是手机模式 ,有些低版本浏览器可能没有这个功能. ----------------------------- ...
- 让nodepad++编辑时链接能双击打开
让nodepad++编辑时链接能双击打开,Notepad++自动把代码或编辑状态里的链接或URL地址转成可点击的链接,当你双击该URL会打开相应的网页地址,不用复制地址到浏览器打开了,非常方便好用. ...
- c++的友元类、方法及其益处
在java中,我们知道除了public和private,protected外,还有默认的包可见性访问级别,虽然如此,很多时候出于早期设计缺陷的原因,我们需要访问一些包或者protected可见性级别的 ...
- 20145310《网络对抗技术》Exp6 信息搜集技术
实验内容 本次实验的目标是掌握信息搜集的最基础技能.具体有 (1)各种搜索技巧的应用 (2)DNS IP注册信息的查询 (3)基本的扫描技术:主机发现.端口扫描.OS及服务版本探测.具体服务的查点 ( ...
- 20145311王亦徐《网络对抗技术》MAL_逆向与Bof基础
20145311王亦徐<网络对抗技术>MAL_逆向与Bof基础 实践目标 运行一个可执行文件,通过逆向或者Bof技术执行原本不应该执行的代码片段采用的两种方法: 1.利用foo函数的Bof ...