Advertisement
erfanul007

UVa 10738

Dec 31st, 2019
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // #pragma GCC optimize("Ofast,no-stack-protector")
  5. // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  6. // #pragma GCC optimize("unroll-loops")
  7.  
  8. typedef unsigned long long ull;
  9. typedef long long ll;
  10. typedef long double lld;
  11. typedef vector<int> vi;
  12. typedef vector<ll> vll;
  13. typedef vector<vi> vvi;
  14. typedef pair<int,int > pii;
  15. typedef pair<ll,ll > pll;
  16. typedef vector< pii > vpii;
  17. typedef vector< pll > vpll;
  18. typedef set<int> sti;
  19.  
  20. #define sc scanf
  21. #define pf printf
  22. #define sci(n) scanf("%d",&n)
  23. #define scii(n,m) scanf("%d %d",&n,&m)
  24. #define scl(n) scanf("%lld",&n)
  25. #define scd(n) scanf("%lf",&n)
  26. #define scs(s) scanf("%s",s)
  27. #define pfi(n) printf("%d",n)
  28. #define pfl(n) printf("%lld",n)
  29. #define pff(n) cout<<n
  30. #define spc printf(" ")
  31. #define line printf("\n")
  32. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  33. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  34. #define cspf(i) printf("Case %d: ", i)
  35. #define vout(v) for(int w=0;w<v.size();w++){if(w) cout<<' '; cout<<v[w];}
  36. #define clr(a,x) memset(a,x,sizeof(a))
  37. #define tp(v,j) get<j>(v)
  38. #define pb push_back
  39. #define mp make_pair
  40. #define mt make_tuple
  41. #define ff first
  42. #define ss second
  43. #define all(v) v.begin(),v.end()
  44. #define rall(v) v.rbegin(),v.rend()
  45. #define read() freopen("input.txt", "r", stdin)
  46. #define write() freopen("output.txt", "w", stdout)
  47. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL);
  48. /// Constants
  49. #define eps 1e-6
  50. #define PI acos(-1.0) // 3.1415926535897932
  51. #define MAX (ll)2147483647
  52. #define MAXn 1000009
  53.  
  54. int GCD(int a, int b) { return b == 0 ? a : GCD(b , a % b); }
  55. ll LCM(ll a, ll b) { return a * (b/GCD(a, b)); }
  56.  
  57. vi prime;
  58. bool chk[MAXn];
  59.  
  60.  
  61. void seive()
  62. {
  63. clr(chk,true);
  64. chk[0]=chk[1]=false;
  65. for(int i=4;i<MAXn;i+=2) chk[i]=false;
  66. for(int i=3;i<=MAXn/i;i+=2){
  67. if(!chk[i]) continue;
  68. for(int j=i*i;j<MAXn;j+=(2*i)) chk[j]=false;
  69. }
  70. prime.pb(2);
  71. for(int i=3;i<MAXn;i+=2){
  72. if(chk[i]) prime.pb(i);
  73. }
  74. }
  75.  
  76. int mu[MAXn];
  77. int M[MAXn];
  78.  
  79. void mobious()
  80. {
  81. mu[1]=1;
  82. for(int i=2;i<MAXn-8;i++){
  83. int k=i,cnt=0;
  84. bool f=false;
  85. for(int j=0;prime[j]<=k/prime[j];j++){
  86. if(k%prime[j]==0){
  87. k/=prime[j];
  88. if(k%prime[j]==0){
  89. f=true;
  90. break;
  91. }
  92. cnt++;
  93. }
  94. }
  95. if(f) continue;
  96. if(k>1) cnt++;
  97. if(cnt&1) mu[i]=-1;
  98. else mu[i]=1;
  99. }
  100. for(int i=1;i<MAXn-8;i++) M[i]=M[i-1]+mu[i];
  101. }
  102.  
  103.  
  104. int main()
  105. {
  106. #ifdef VAMP
  107. clock_t tStart = clock();
  108. freopen("input.txt", "r", stdin);
  109. freopen("output.txt", "w", stdout);
  110. #endif
  111.  
  112. seive();
  113. mobious();
  114.  
  115. while(1){
  116. int n;
  117. sci(n);
  118. if(!n) break;
  119. pf("%8d%8d%8d\n",n,mu[n],M[n]);
  120. }
  121.  
  122.  
  123. #ifdef VAMP
  124. fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
  125. #endif
  126.  
  127. return 0;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement