Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <sstream>
- #include <string>
- #include <vector>
- #include <queue>
- #include <set>
- #include <map>
- #include <cstdio>
- #include <cstdlib>
- #include <cctype>
- #include <cmath>
- #include <cstring>
- #include <ctime>
- using namespace std;
- typedef unsigned long long LL;
- #define FOR(k,a,b) for(LL k(a); k < (b); ++k)
- #define FORD(k,a,b) for(int k(a-1); k >= (b); --k)
- #define REP(k,a) for(int k=0; k < (a); ++k)
- #define ABS(a) ((a)>0?(a):-(a))
- LL inverse(LL p,LL n)
- {
- LL res=1;
- LL pow=p-2;
- LL tmp=n;
- while(pow)
- {
- if(pow&1)
- res*=tmp;
- res%=p;
- pow>>=1;
- tmp*=tmp;
- tmp%=p;
- }
- return res;
- }
- int main()
- {
- #ifdef HOME
- freopen ("in.txt","r",stdin);
- freopen ("out.txt","w",stdout);
- #endif
- int T,p;
- scanf("%d",&T);
- REP(testCase,T)
- {
- set<pair<LL,LL> > S,S2,S3,Pred,Pred2;
- set<pair<LL,LL> >::iterator it,sit;
- scanf("%d",&p);
- Pred.insert(make_pair(1,1));
- for(LL k=1;k*k<p+4;++k)
- {
- LL candidate=(p+1)/k;
- if(candidate*k==p+1)
- {
- Pred.insert(make_pair(candidate,1));
- }
- ++candidate;
- LL candidate_a=candidate*k-p;
- if(!((p+candidate+candidate_a)%(candidate*candidate_a)))
- {
- Pred.insert(make_pair(candidate,candidate_a));
- }
- }
- for(LL k=2;k*k<p+4;++k)
- {//k az a b
- LL candidate_a=k-(p%k);
- if(!((p+k+candidate_a)%(k*candidate_a)))
- {
- Pred.insert(make_pair(k,candidate_a));
- }
- }
- for(LL k=1;k*k<2*(p+2);++k)
- {
- LL candidate_b=inverse(p,k),candidate_a;
- LL tmp=(k*candidate_b-1)/p;
- if(tmp && !((candidate_b+1)%tmp))
- {
- candidate_a=(candidate_b+1)/tmp;
- Pred2.insert(make_pair(candidate_b,candidate_a));
- }
- else
- {
- int aaa=1;
- }
- }
- // FOR(a,1,sqrt((double) p)+4)
- // FOR(b,a,p+a+1)
- FOR(a,1,p+2)
- FOR(b,a,p+a+2)
- {
- LL t=p+a+b*p,t2=a*b;
- if(!(t%t2) && a%p && b%p)
- {
- // if(b%p)
- // {//(a,b)=(a,p)=(b,p)=1
- // //S.insert(make_pair(a-p,b-p));
- // //if(a!=b)
- // S.insert(make_pair(b,a));
- // }
- // else if(a%p)
- // {
- //S2.insert(make_pair(a-p,b-p));
- //if(a!=b)
- S.insert(make_pair(b,a));
- // }
- // else
- // {
- // S3.insert(make_pair(a,b));
- // if(a!=b)
- // S3.insert(make_pair(b,a));
- // }
- }
- }
- printf("%d\n",p);
- //sit=Pred.begin();
- //bool ok=true;
- for(it=S.begin();it!=S.end();++it/*,++sit*/)
- {
- const LL & b=it->first,a=it->second;
- LL t=(p+a+b*p)/(a*b);
- 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);
- //printf("%d %d\n",sit->first,sit->second);
- // if(it->first!=sit->first || it->second!=sit->second)
- // ok=false;
- }
- // printf("----------------------\n");
- // print_primes_interval(1,sqrt((double) p)+3);
- // printf("\n");
- // print_primes_interval(p,p+sqrt((double) p)+2);
- // printf("\n----------------------\n",p);
- // if(ok)
- // printf("ok\n");
- // else
- // printf("not ok\n");
- printf("----------------------\n",p);
- //printf("%d\n",S.size());
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment