Advertisement
MarioYC

visible points 3D

Dec 6th, 2012
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cmath>
  4. #include <iostream>
  5. #include <sstream>
  6. #include <algorithm>
  7. #include <string>
  8. #include <vector>
  9. #include <queue>
  10. #include <stack>
  11. #include <map>
  12. #include <set>
  13.  
  14. using namespace std;
  15.  
  16. #define MAXN 1000000
  17.  
  18. int mu[MAXN + 1],factor[MAXN + 1];
  19.  
  20. long long visible(int X, int Y){
  21.     if(X == 0 || Y == 0) return 1;
  22.    
  23.     long long ret = 2;
  24.    
  25.     for(int i = 1;i <= min(X,Y);++i)
  26.         ret += mu[i] * (X / i) * (Y / i);
  27.    
  28.     return ret;
  29. }
  30.  
  31. long long visible(int X, int Y, int Z){
  32.     long long ret = 0;
  33.    
  34.     for(int i = 1;i <= X;++i)
  35.         ret += mu[i] * (X / i) * (Y / i) * (Z / i);
  36.    
  37.     return ret;
  38. }
  39.  
  40. int main(){
  41.     ios::sync_with_stdio(0);
  42.    
  43.     memset(factor,-1,sizeof factor);
  44.     mu[1] = 1;
  45.    
  46.     for(int i = 2;i <= MAXN;++i){
  47.         if(factor[i] == -1){
  48.             mu[i] = -1;
  49.            
  50.             if(i <= MAXN / i)
  51.                 for(int j = i*i;j <= MAXN;j += i)
  52.                     factor[j] = i;
  53.         }else{
  54.             int cont = 0,aux = i,p = factor[i];
  55.            
  56.             while(aux % p == 0 && cont < 2){
  57.                 aux /= p;
  58.                 ++cont;
  59.             }
  60.            
  61.             if(cont == 2) mu[i] = 0;
  62.             else mu[i] = -mu[i / p];
  63.         }
  64.     }
  65.    
  66.     int X,Y,Z;
  67.    
  68.     cin >> X >> Y >> Z;
  69.    
  70.     long long ans = visible(X,Y,Z) + visible(X,Y) + visible(Y,Z) + visible(Z,X);
  71.    
  72.     if(X >= 1) --ans;
  73.     if(Y >= 1) --ans;
  74.     if(Z >= 1) --ans;
  75.    
  76.     cout << ans << endl;
  77.    
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement