2 条题解
-
0
终于过了,纪念一下。
#include<bits/stdc++.h> #define int long long #define INF 0x3f3f3f using namespace std; int n; int cnt,a[300001],now=2; bool primed(int x){ if(x<2)return 0; for(int i=2;i*i<=x;i++) if(x%i==0)return 0; return 1; } signed main(){ cin>>n; if(n==1){ cout<<"0"; return 0; } else if(primed(n)){ cout<<n-1; return 0; } double m=n; while(n!=1){ bool flag=1; while(n%now==0){ n/=now; if(flag){ a[++cnt]=now; flag=0; } } now++; } for(int i=1;i<=cnt;i++) m*=(1-1.0/a[i]); int k=m; cout<<k; return 0; }
神奇的是,以下代码会 TLE:
#include<bits/stdc++.h> #define int long long #define INF 0x3f3f3f using namespace std; int n; int cnt,a[300001],now=2; bool primed(int x){ if(x<2)return 0; for(int i=1/*here*/;i*i<=x;i++) if(x%i==0)return 0; return 1; } signed main(){ cin>>n; if(n==1){ cout<<"0"; return 0; } else if(primed(n)){ cout<<n-1; return 0; } double m=n; while(n!=1){ bool flag=1; while(n%now==0){ n/=now; if(flag){ a[++cnt]=now; flag=0; } } now++; } for(int i=1;i<=cnt;i++) m*=(1-1.0/a[i]); int k=m; cout<<k; return 0; }
-
0
C++ :
#include<cstdio> #include<iostream> #include<cmath> using namespace std; long long len=0,n; double ans,a[100000]={0}; bool judge(long long x) { for(int i=2;i<=sqrt(x);i++) if(x%i==0) return 0; return 1; } int main() { scanf("%d",&n); if(!n) { cout<<0; return 0; } ans=n; if(judge(n)) { ans-=1; cout<<(long long)ans; return 0; } long long j=2; while(n!=1) { if(!(n%j)) { n/=j; if(a[len]!=j) a[++len]=j; if(judge(n)) { if(n!=j) a[++len]=n; break; } } else j++; } for(int i=1;i<=len;i++) ans*=(1-1/a[i]); cout<<(long long)ans; return 0; }
- 1
信息
- ID
- 1215
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 10
- 标签
- 递交数
- 28
- 已通过
- 1
- 上传者