QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#496437 | #9139. Prefix Divisible by Suffix | ucup-team1231# | WA | 2191ms | 3612kb | C++14 | 2.9kb | 2024-07-28 10:14:50 | 2024-07-28 10:14:51 |
Judging History
answer
#pragma GCC optimize("Ofast","funroll-all-loops","ffast-math")
#include <bits/stdc++.h>
using namespace std;
#define SZ 1333333
#define fi first
#define se second
typedef long long ll;
typedef __int128 lll;
ll n,c;
ll um;
//(x*po+lo)%mo==0
ll po[30],mo[30],lo[30]; int sn;
int dc[30];
ll px[30],py[30];
ll ans=0;
ll euclid(ll a,ll b,ll&x,ll&y) {
if(!b) return x=1,y=0,a;
ll d=euclid(b,a%b,y,x);
return y-=a/b*x,d;
}
void dfs(int cur,ll p,ll q,int coef=1) {
q%=p; if(q<0) q+=p;
if(q>um) return;
if(um/p<=20) {
for(ll w=q;w<=um;w+=p) {
if(!w) continue;
for(int u=cur;~u;--u)
if((w%mo[u]*po[u]+lo[u])%mo[u]==0) goto bad;
ans+=coef;
// cerr<<"found "<<w<<"\n";
bad:;
}
return;
}
if(cur<0) {
// cerr<<"haha\n";
ll rst=(um-q)/p+(q!=0);
ans+=coef*rst;
return;
}
dfs(cur-1,p,q,coef);
if(!dc[cur]) {
ll g=__gcd(po[cur],mo[cur]);
if(lo[cur]%g) dc[cur]=-1;
else {
lo[cur]/=g, po[cur]/=g, mo[cur]/=g;
ll x,y;
euclid(po[cur],mo[cur],x,y);
//x=inv(po[cur],mo[cur])
ll RHS=lo[cur]*x%mo[cur];
po[cur]=1; lo[cur]=RHS;
dc[cur]=1;
// cerr<<"dec:"<<mo[cur]<<"EZ\n";
}
}
if(dc[cur]!=-1) {
ll a=q,m=p;
ll b=-lo[cur],n=mo[cur];
if(n>m) swap(a,b),swap(m,n);
// cerr<<m<<" "<<n<<"++\n";
ll x,y,g=euclid(m,n,x,y);
if((a-b)%g) return;
x=(b-a)%n*x%n/g*m+a;
// if(x<0) x+=m*n/g;
dfs(cur-1,m*n/g,x,-coef);
}
}
int main() {
// cin>>n>>c;
n=1e14,c=1e4;
// ll aa=0;
for(ll sf=0;sf<=10000000;++sf) {
int ss[20],g=sf; sn=0;
memset(ss,0,sizeof ss);
while(g) ss[sn++]=g%10,g/=10;
// cout<<sn<<"\n";
// cerr<<sn<<" "<<pf<<"\n";
for(ll rl=1,rlp=10;;++rl,rlp*=10) {
if(sf>=rlp) continue;
// cerr<<rl<<","<<rlp<<"+"<<sf<<"\n";
if((sf+c)*rlp+sf>n) break;
//x mod (sf+c)=0
um=(n-sf)/rlp;
ll po=1,low=0,rf=sf,rp=rlp;
for(int o=rl-1;o>=0;--o) {
// ++aa;
//(x*po+low) mod (rf+c)=0
// if(sf==12345&&rl==7)
// cout<<sf<<","<<rl<<":"<<po<<","<<low<<","<<rf<<"\n";
::po[o]=po%(rf+c);
::lo[o]=low;
::mo[o]=rf+c;
::dc[o]=0;
// cerr<<"mo:"<<::mo[o]<<"\n";
// cerr<<rf+c<<"Jajan";
rp/=10;
rf-=rp*ss[o];
po*=10; low=low*10+ss[o];
}
// assert(::po[rl-1]==0);
dfs(rl-2,mo[rl-1],-lo[rl-1]);
}
}
cout<<ans<<"\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2191ms
memory: 3612kb
input:
20 1
output:
35400402243
result:
wrong answer 1st numbers differ - expected: '2', found: '35400402243'