iscsi

short II.

Dec 7th, 2011
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.13 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <string>
  5. #include <vector>
  6. #include <queue>
  7. #include <set>
  8. #include <map>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cctype>
  12. #include <cmath>
  13. #include <cstring>
  14. #include <ctime>
  15. using namespace std;
  16. typedef unsigned long long LL;
  17. #define FOR(k,a,b) for(LL k(a); k < (b); ++k)
  18. #define FORD(k,a,b) for(int k(a-1); k >= (b); --k)
  19. #define REP(k,a) for(int k=0; k < (a); ++k)
  20. #define ABS(a) ((a)>0?(a):-(a))
  21.  
  22. LL inverse(LL p,LL n)
  23. {
  24.     LL res=1;
  25.     LL pow=p-2;
  26.     LL tmp=n;
  27.     while(pow)
  28.     {
  29.         if(pow&1)
  30.             res*=tmp;
  31.         res%=p;
  32.         pow>>=1;
  33.         tmp*=tmp;
  34.         tmp%=p;
  35.     }
  36.     return res;
  37. }
  38.  
  39. int main()
  40. {
  41. #ifdef HOME
  42.     freopen ("in.txt","r",stdin);
  43.     freopen ("out.txt","w",stdout);
  44. #endif 
  45.     int T,p;
  46.     scanf("%d",&T);
  47.     REP(testCase,T)
  48.     {
  49.         set<pair<LL,LL> > S,S2,S3,Pred,Pred2;
  50.         set<pair<LL,LL> >::iterator it,sit;
  51.         scanf("%d",&p);
  52.         Pred.insert(make_pair(1,1));
  53.         for(LL k=1;k*k<p+4;++k)
  54.         {
  55.             LL candidate=(p+1)/k;
  56.             if(candidate*k==p+1)
  57.             {
  58.                 Pred.insert(make_pair(candidate,1));
  59.             }
  60.             ++candidate;
  61.             LL candidate_a=candidate*k-p;
  62.             if(!((p+candidate+candidate_a)%(candidate*candidate_a)))
  63.             {
  64.                 Pred.insert(make_pair(candidate,candidate_a));
  65.             }
  66.         }
  67.         for(LL k=2;k*k<p+4;++k)
  68.         {//k az a b
  69.             LL candidate_a=k-(p%k);
  70.             if(!((p+k+candidate_a)%(k*candidate_a)))
  71.             {
  72.                 Pred.insert(make_pair(k,candidate_a));
  73.             }
  74.         }
  75.         for(LL k=1;k*k<2*(p+2);++k)
  76.         {
  77.             LL candidate_b=inverse(p,k),candidate_a;
  78.             LL tmp=(k*candidate_b-1)/p;
  79.             if(tmp && !((candidate_b+1)%tmp))
  80.             {
  81.                 candidate_a=(candidate_b+1)/tmp;
  82.                 Pred2.insert(make_pair(candidate_b,candidate_a));
  83.             }
  84.             else
  85.             {
  86.                 int aaa=1;
  87.             }
  88.         }
  89.         //      FOR(a,1,sqrt((double) p)+4)
  90.         //      FOR(b,a,p+a+1)
  91.         FOR(a,1,p+2)
  92.         FOR(b,a,p+a+2)
  93.         {
  94.             LL t=p+a+b*p,t2=a*b;
  95.             if(!(t%t2) && a%p && b%p)
  96.             {
  97.  
  98.                 //              if(b%p)
  99.                 //              {//(a,b)=(a,p)=(b,p)=1
  100.                 //                  //S.insert(make_pair(a-p,b-p));
  101.                 //                  //if(a!=b)
  102.                 //                  S.insert(make_pair(b,a));
  103.                 //              }
  104.                 //              else if(a%p)
  105.                 //              {
  106.                 //S2.insert(make_pair(a-p,b-p));
  107.                 //if(a!=b)
  108.                 S.insert(make_pair(b,a));
  109.                 //              }
  110.                 //              else
  111.                 //              {
  112.                 //                  S3.insert(make_pair(a,b));
  113.                 //                  if(a!=b)
  114.                 //                      S3.insert(make_pair(b,a));
  115.                 //              }
  116.             }
  117.         }
  118.         printf("%d\n",p);
  119.         //sit=Pred.begin();
  120.         //bool ok=true;
  121.         for(it=S.begin();it!=S.end();++it/*,++sit*/)
  122.         {  
  123.             const LL & b=it->first,a=it->second;
  124.             LL t=(p+a+b*p)/(a*b);
  125.             printf("%lld %lld %lld %lld %lld %lld %lld\n",b,a,t,(b*t-1)/p,/*t/((b*t-1)/p)+1*/(b+1)/a,a*t,(a*t)%p); 
  126.             //printf("%d %d\n",sit->first,sit->second);
  127.             //          if(it->first!=sit->first || it->second!=sit->second)
  128.             //              ok=false;
  129.         }
  130.         //      printf("----------------------\n");
  131.         //      print_primes_interval(1,sqrt((double) p)+3);
  132.         //      printf("\n");
  133.         //      print_primes_interval(p,p+sqrt((double) p)+2);
  134.         //      printf("\n----------------------\n",p);
  135.  
  136.         //      if(ok)
  137.         //          printf("ok\n");
  138.         //      else
  139.         //          printf("not ok\n");
  140.         printf("----------------------\n",p);
  141.         //printf("%d\n",S.size());
  142.     }
  143.     return 0;
  144. }
Advertisement
Add Comment
Please, Sign In to add comment