QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#114892 | #1860. Historic Breakthrough | Crysfly | AC ✓ | 61ms | 3604kb | C++17 | 3.4kb | 2023-06-23 22:08:08 | 2023-06-23 22:08:09 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ull unsigned long long
#define i128 __int128
#define int long long
using namespace std;
inline i128 read()
{
char c=getchar();i128 x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 200005
#define inf 0x3f3f3f3f
mt19937_64 rnd(114514);
// lazy to write these
__int128 mul(__int128 a,__int128 b,__int128 p)
{
__int128 mul=a,res=0;
while (b)
{
if (b&1) res=(res+mul)%p;
mul=(mul+mul)%p,b>>=1;
}
return res;
}
__int128 qpow(__int128 a,__int128 b,__int128 p)
{
__int128 mul=a,res=1;
while (b)
{
if (b&1) res=::mul(res,mul,p);
mul=::mul(mul,mul,p),b>>=1;
}
return res;
}
__int128 gcd(__int128 x,__int128 y)
{
if (y==0) return x;
return gcd(y,x%y);
}
__int128 get_pow(__int128 a,int b,__int128 c)
{
__int128 mul=1;
bool op=0;
for (int i=1;i<=b;++i)
{
if (mul<=c/a) mul*=a;
else op=1;
}
return op?c+1:mul;
}
i128 pw[999];
bool isp(__int128 x)
{
if (x%2==0||x%3==0||x%5==0||x%7==0||x%11==0) return 0;
__int128 a,d=x-1;
int res=0;
while (!(d&1)) d>>=1,res++;
for (int i=1;i<=10;++i)
{
a=rnd()%1000000000+1,pw[0]=qpow(a,d,x);
for (int j=1;j<=res;++j) pw[j]=mul(pw[j-1],pw[j-1],x);
if (pw[res]!=1) return 0;
for (int j=res-1;j>=0;--j)
{
if (pw[j]==x-1) break;
if (pw[j]!=1) return 0;
}
}
return 1;
}
__int128 rtd(__int128 x,__int128 d)
{
__int128 y=0;
for (int i=log(2e18)/log(2);i>=0;--i)
if (y+(1ll<<i)<=2e18&&get_pow(y+(1ll<<i),d,x)<=x)
y+=(1ll<<i);
return y;
}
int B=45000,BB=(B+1)*(B+1);
int pri[maxn],tot;
bool vis[maxn];
void sieve(int n){
For(i,2,n){
if(!vis[i]) pri[++tot]=i;
For(j,1,tot){
int x=i*pri[j];
if(x>n)break;
vis[x]=1;
if(i%pri[j]==0)break;
}
}
}
map<i128,int>mp;
int cnt;
i128 m,m2;
int V=1e18;
void solve(i128 x){
// cout<<"solve "<<(int)x<<'\n';
if(x==1)return;
if(isp(x)){
mp[x]=1;
return;
}
For(i,2,10){
i128 d=rtd(x,i);
if(isp(d) && get_pow(d,i,x)==x){
mp[d]=1;
return;
}
}
while(1){
i128 a=rnd()%V+1;
while(gcd(a,m)!=1) a=rnd()%V+1;
i128 qp=qpow(a,m,x);
if(qp!=1){
i128 tmp=gcd(x,qp-1);
solve(tmp);
return;
}
i128 pw0=qpow(a,m2,x);
i128 pw1=mul(pw0,pw0,x);
int step=0;
while(1){
if(pw0==-1 || pw0==x-1)break;
if(pw0!=1 && pw1==1){
i128 tmp=gcd(pw0+1,x);
solve(tmp);
solve(x/tmp);
return;
}
pw0=pw1;
pw1=mul(pw0,pw0,x);
++step;
if(step>cnt)break;
}
}
}
void work()
{
mp.clear();
i128 x=read()*2,X=x; m=X;
cnt=0;
while(x%2==0)x/=2,++cnt;
m2=x;
x=X;
For(i,1,tot)
while(x%pri[i]==0)x/=pri[i],mp[pri[i]]=1;
solve(x);
vector<i128>o;
for(auto it:mp) o.pb(it.fi);
// for(auto x:o) cout<<(long long)x<<'\n';
i128 now=X;
long long res=1;
Rep(i,(int)o.size()-1,0){
int cc=0;
while(now%o[i]==0)now/=o[i],++cc;
if(!cc)continue;
For(j,1,(cc+1)/2)res*=o[i];
// cout<<"cc "<<cc<<endl;
now/=(o[i]-1);
}
cout<<res<<"\n";
}
signed main()
{
sieve(B);
int T=read();
while(T--)work();
return 0;
}
/*
3
20
21
475750381222420656586462245096576000
*/
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3556kb
input:
3 20 21 475750381222420656586462245096576000
output:
10 7 1497700821900508526
result:
ok 3 number(s): "10 7 1497700821900508526"
Test #2:
score: 0
Accepted
time: 47ms
memory: 3532kb
input:
51 348387408908517538156281238966340503 269891120302452381431351214335847781 747207543121624879797402427368860 500118165772005573992050274078796601 376563350255195175098956276198783051 855996192374691515214841787085600 491448606692239765059794615991064231 123619467864337410141102480048000000 7114827...
output:
834730386302688203 734698741393303847 38657773487574029 1000118158791255599 867828727636041299 41376351752391209 991411727479799147 819415677966571060 533472702079376326 419694411774324997 119851595982618319 24024477947405473 730267680763188643 269435681305057117 809387811759102827 29392724088327775...
result:
ok 51 numbers
Test #3:
score: 0
Accepted
time: 35ms
memory: 3540kb
input:
50 590955592280751522125185760551589472 450753984250583112023852704149662080 196704025354160782063198166237303808 382785853244719627595443384812477912 40522659517926585041466149305181616 26478235572251423131073298958930080 490320199321080674802144988571268192 110281951063110963040645709560838400 948...
output:
1331689688366264319 949479804339042269 1090685758659983022 945075124476539231 434862903013111412 398589648217243506 1012639928054749381 699351669356204744 543210198772784757 1132463196576070170 848907776403266445 1930255754904417056 1189528317659705086 686463867402133171 102891055039662950 182071571...
result:
ok 50 numbers
Test #4:
score: 0
Accepted
time: 25ms
memory: 3580kb
input:
50 276259542446423651625925027373027232 393684955823722570867768699571572176 857720676067612917869599746201489600 17110455728330975252747068107907200 542281457444687912305057901366280320 2654306616117951734640416629182720 322861266726126116829643702477914336 298853927939020940780632877440807680 7898...
output:
1293520230715335156 1086778493949362559 1464686748629892505 190080489690965899 1545864800321934334 76672170019366097 1024398581737711713 1096526389684540348 2349064908930748272 50307494154045329 445092096339592380 1435004850383139296 1529324330815083956 2097596248514948892 760541100765245579 3818739...
result:
ok 50 numbers
Test #5:
score: 0
Accepted
time: 61ms
memory: 3604kb
input:
50 453008189735946954708861108359363203 551025652219715865084914059564383721 786164844307406583446593304065657003 610291465035142731460915809600409753 706864586054180662022440079345324653 570551915704950184495149575882325703 864916087207438864260538795023947461 421455605824822507806251352877855381 3...
output:
951848926811336963 1049786313703618319 1253925710963298323 1104799950249041903 1189003436541863543 1068224616553045163 1315230844534478567 918101961467050247 802814943898092227 762571582574907779 831979843661865359 797606718229530359 938154503358815423 1303037683800527639 793773369441477119 14021898...
result:
ok 50 numbers
Test #6:
score: 0
Accepted
time: 41ms
memory: 3568kb
input:
50 1300378470060305026424038382191232 6956378996245323843606514078615500 589244226744677712771854578698400 237091357130763153045978263910123672 161751450022115587601924824730219160 132669464182049885124281942384188456 67134267644722497849437741098688712 286785555483759509945063633526861 327655419420...
output:
51004138467328681 117952585187174711 34329342804633713 688610038029305417 568773901505426053 515110919481552113 366427282885665097 23949386230845223 255990812380074931 48745809601284947 45479093200495939 363088169939630143 116834934318262613 311344543295176663 115798704650850539 1071834160097733031 ...
result:
ok 50 numbers