SGU102
来源:互联网 发布:查询淘宝关键词排名 编辑:程序博客网 时间:2024/05/01 15:44
求小于N的整数中与N互质的数的个数
由于范围比较小,暴力GCD应该是可以过得
但是更好的方法是欧拉函数
//Lib#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<ctime>#include<iostream>#include<algorithm>#include<vector>#include<string>#include<queue>using namespace std;//Macro#define rep(i,a,b) for(int i=a,tt=b;i<=tt;i++)#define rrep(i,a,b) for(int i=a,tt=b;i>=tt;i--)#define erep(i,e,x) for(int i=x;i;i=e[i].next)#define irep(i,x) for(__typedef(x.begin()) i=x.begin();i!=x.end();i++)#define read() (strtol(ipos,&ipos,10))#define sqr(x) ((x)*(x))#define pb push_back#define PS system("pause");typedef long long ll;typedef pair<int,int> pii;const int oo=~0U>>1;const double inf=1e20;const double eps=1e-6;string name="",in=".in",out=".out";//Varconst int maxn=10000;int p[10008],e[10008],vis[10008],cnt,n;void GetPrime(){e[1]=1;rep(i,2,n){if(!vis[i])p[++cnt]=i,e[i]=i-1;for(int j=1;j<=cnt&&i*p[j]<=n;j++){vis[i*p[j]]=p[j];e[i*p[j]]=e[i]*e[p[j]];if(i%p[j]==0){e[i*p[j]]=e[i]*p[j];break;}}}}void Work(){scanf("%d",&n);GetPrime();cout<<e[n]<<endl;}int main(){//freopen((name+in).c_str(),"r",stdin);//freopen((name+out).c_str(),"w",stdout);//Init();Work();return 0;}
- SGU102
- sgu102
- sgu102
- SGU102 Coprimes
- sgu102:Coprimes
- SGU102 Coprimes
- SGU102 Coprimes
- SGU102 Coprimes
- SGU102 Coprimes
- sgu102-欧拉函数
- SGU102 水题 An easy problem
- SGU102 欧拉函数 傻逼题
- SGU102——Coprimes (又见欧几里得)
- 特殊引用$this的使用
- PHP发送电子邮件
- 去除HTML标记
- 【十】 进程间通信——[System V IPC对象]消息队列(message queue)
- 邻接表深度优先遍历和广度遍历
- SGU102
- 读书笔记_键盘嗅探器(1)
- ANC 主动噪声消除-参考文章
- 【十一】 进程间通信——[System V IPC对象]信号灯(semaphore)
- erlang重新开张
- 黑马程序员_银行业务调度系统
- 黑马程序员_注解
- PHP面向对象开发的学习
- php面向对象小案例