iscsi

euler 362 temp

Dec 12th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <string>
  5. #include <vector>
  6. #include <list>
  7. #include <queue>
  8. #include <stack>
  9. #include <set>
  10. #include <map>
  11. #include <cstdio>
  12. #include <cstdlib>
  13. #include <cctype>
  14. #include <cmath>
  15. #include <cstring>
  16. #include <ctime>
  17. using namespace std;
  18. typedef unsigned long long LL;
  19. #define FOR(k,a,b) for(int k(a); k < (b); ++k)
  20. #define FORD(k,a,b) for(int k(a-1); k >= (b); --k)
  21. #define REP(k,a) for(int k=0; k < (a); ++k)
  22. #define REPD(k,a) for(int k=a-1; k >-1; --k)
  23. #define ABS(a) ((a)>0?(a):-(a))
  24.  
  25. struct ITEM
  26. {
  27.     LL val;
  28.     LL counter;
  29.     vector<int> expo;
  30. };
  31.  
  32. // int calc(vector<int>& v,map<vector<int>,int>& m)
  33. // {
  34. //
  35. // }
  36.  
  37. int main()
  38. {
  39. #ifdef HOME
  40. //  freopen ("in.1","r",stdin);
  41. //  freopen ("out.txt","w",stdout);
  42. #endif
  43.     const int mMax=10002;
  44.     const LL goal=1e10;
  45.     vector<bool> sieve(mMax,true);
  46.  
  47.     list<ITEM> l;
  48.     list<ITEM>::iterator lit,lend;
  49.     map<vector<int>,int> m,mm;
  50.  
  51.     FOR(i,2,mMax)
  52.     {
  53.         if(sieve[i])
  54.         {
  55.             for(int j=2*i;j<mMax;j+=i)
  56.             {
  57.                 sieve[j]=false;
  58.             }
  59.         }
  60.     }
  61.     FOR(i,2,mMax)
  62.     {
  63.         if(!sieve[i])
  64.             continue;
  65.         LL tmp=i;
  66.         LL ctr=0;
  67.         int expo=1;
  68.         while(tmp*i<=goal)
  69.         {
  70.             tmp*=i;
  71.             expo++;
  72.         }
  73.         LL maxtmp=tmp;
  74.         LL maxexpo=expo;
  75.         while(tmp>1)
  76.         {
  77.             LL subctr=goal/tmp-ctr;
  78.             ctr+=subctr;
  79.             ITEM item;
  80.             item.val=tmp;
  81.             item.counter=ctr;
  82.             item.expo.push_back(expo);
  83.             l.push_back(item);
  84.             tmp/=i;
  85.             --expo;
  86.         }
  87.         for(lit=l.begin();lit!=l.end();)
  88.         {
  89.             if(!(lit->val%i))
  90.                 break;
  91.             ITEM& act=*lit;
  92.             if(act.val*i>goal)
  93.             {
  94.                 sort(act.expo.begin(),act.expo.end());
  95.                 ++m[act.expo];
  96.                 l.erase(lit++);
  97.                 continue;
  98.             }
  99.             tmp=maxtmp;
  100.             expo=maxexpo;
  101.             ctr=0;
  102.             while(tmp>1)
  103.             {
  104.                 if(tmp*act.val<=goal)
  105.                 {
  106.                     ITEM cand;
  107.                     cand.val=tmp*act.val;
  108.                     cand.counter=act.counter/tmp-ctr;
  109.                     //act.counter-=cand.counter;
  110.                     ctr+=cand.counter;
  111.                     cand.expo=act.expo;
  112.                     cand.expo.push_back(expo);
  113.                     if(cand.counter && cand.val*(i)<goal)
  114.                     {
  115.                         l.push_back(cand);
  116.                     }
  117.                     else
  118.                     {
  119.                         sort(cand.expo.begin(),cand.expo.end());
  120.                         ++m[cand.expo];
  121.                     }
  122.                 }
  123.                 tmp/=i;
  124.                 --expo;
  125.             }
  126.             ++lit;
  127.         }
  128.     }
  129.     return 0;
  130. }
  131.  
  132.  
Advertisement
Add Comment
Please, Sign In to add comment