A plurality of sets of data, given a prime \ (P \) , require that all \ (X \) such that \ (f (x) = \ min_ {K = 2} ^ XF (K) \) , where \ (f (x) = x ^ {- 1} \ )
All \ (P \) in ([1, 10 ^ 9] \) \ uniformly in the selected
Solution
Obviously inverse sequence symmetrical relationship
Thus the root of the enumeration, the back half of the symmetrical output to
Why is this my problem card for an hour :(
Beginning enumeration border written \ (\ sqrt p \) how would go through
I later found could be a brisk
#include <bits/stdc++.h>
using namespace std;
#define int long long
int a[1000005],p,t;
signed main() {
ios::sync_with_stdio(false);
cin>>t;
while(t--) {
cin>>p;
vector <pair<int,int> > v;
int lim=sqrt(p);
a[1]=1;
int mx=1e9,pos=1;
for(int i=2;i<=p;i++) {
a[i]=-(p/i)*a[p%i],
a[i]=(a[i]%p+p)%p;
if(i>=a[i]) break;
mx=min(mx,a[i]);
if(mx==a[i]) {
if(i<a[i])
v.push_back(make_pair(i,a[i]));
}
}
int flag=0;
if(sqrt(p+1) == (int)sqrt(p+1)) flag=1;
cout<<2*v.size()+flag<<endl;
for(int i=0;i<v.size();i++) cout<<v[i].first<<" "<<v[i].second<<endl;
if(flag) cout<<(int)sqrt(p+1)<<" "<<(int)sqrt(p+1)<<endl;
for(int i=v.size()-1;i>=0;--i) cout<<v[i].second<<" "<<v[i].first<<endl;
}
}