QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#507935 | #9139. Prefix Divisible by Suffix | XY_Eleven | TL | 7860ms | 43560kb | C++23 | 5.4kb | 2024-08-07 00:06:59 | 2024-08-07 00:06:59 |
Judging History
answer
#include <bits/stdc++.h>
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
//#pragma GCC optimize(3)
#define DB double
#define LL long long
#define ULL unsigned long long
#define in128 __int128
#define cint const int
#define cLL const LL
#define For(z,e1,e2) for(int z=(e1);z<=(e2);z++)
#define Rof(z,e1,e2) for(int z=(e2);z>=(e1);z--)
#define For_(z,e1,e2) for(int z=(e1);z<(e2);z++)
#define Rof_(z,e1,e2) for(int z=(e2);z>(e1);z--)
#define inint(e) scanf("%d",&e)
#define inll(e) scanf("%lld",&e)
#define inpr(e1,e2) scanf("%d%d",&e1,&e2)
#define in3(e1,e2,e3) scanf("%d%d%d",&e1,&e2,&e3)
#define outint(e) printf("%d\n",e)
#define outint_(e) printf("%d%c",e," \n"[i==n])
#define outint2_(e,e1,e2) printf("%d%c",e," \n"[(e1)==(e2)])
#define outll(e) printf("%lld\n",e)
#define outll_(e) printf("%lld%c",e," \n"[i==n])
#define outll2_(e,e1,e2) printf("%lld%c",e," \n"[(e1)==(e2)])
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return
#define ll(e) (1ll*(e))
#define pb push_back
#define ft first
#define sc second
#define pii pair<int,int>
#define pli pair<LL,int>
#define vct vector
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define sz(ev) ((int)ev.size())
#define debug(x) printf("%s=%d\n",#x,x)
#define x0 __xx00__
#define y1 __yy11__
#define ffo fflush(stdout)
cLL mod=998244353,G=404;
// cLL mod[2]={1686688681ll,1888686661ll},base[2]={166686661ll,188868881ll};
template <typename Type> void get_min(Type &w1,const Type w2) { if(w2<w1) w1=w2; } template <typename Type> void get_max(Type &w1,const Type w2) { if(w2>w1) w1=w2; }
template <typename Type> Type up_div(Type w1,Type w2) { return (w1/w2+(w1%w2?1:0)); }
template <typename Type> Type gcd(Type X_,Type Y_) { Type R_=X_%Y_; while(R_) { X_=Y_; Y_=R_; R_=X_%Y_; } return Y_; } template <typename Type> Type lcm(Type X_,Type Y_) { return (X_/gcd(X_,Y_)*Y_); }
template <typename Type> Type md(Type w1,const Type w2=mod) { w1%=w2; if(w1<0) w1+=w2; return w1; } template <typename Type> Type md_(Type w1,const Type w2=mod) { w1%=w2; if(w1<=0) w1+=w2; return w1; }
void ex_gcd(LL &X_,LL &Y_,LL A_,LL B_) { if(!B_) { X_=1ll; Y_=0ll; return ; } ex_gcd(Y_,X_,B_,A_%B_); X_=md(X_,B_); Y_=(1ll-X_*A_)/B_; } LL inv(LL A_,LL B_=mod) { LL X_=0ll,Y_=0ll; ex_gcd(X_,Y_,A_,B_); return X_; }
template <typename Type> void add(Type &w1,const Type w2,const Type M_=mod) { w1=md(w1+w2,M_); } void mul(LL &w1,cLL w2,cLL M_=mod) { w1=md(w1*md(w2,M_),M_); } template <typename Type> Type pw(Type X_,Type Y_,Type M_=mod) { Type S_=1; while(Y_) { if(Y_&1) mul(S_,X_,M_); Y_>>=1; mul(X_,X_,M_); } return S_; }
template <typename Type> Type bk(vector <Type> &V_) { auto T_=V_.back(); V_.pop_back(); return T_; } template <typename Type> Type tp(stack <Type> &V_) { auto T_=V_.top(); V_.pop(); return T_; } template <typename Type> Type frt(queue <Type> &V_) { auto T_=V_.front(); V_.pop(); return T_; }
template <typename Type> Type bg(set <Type> &V_) { auto T_=*V_.begin(); V_.erase(V_.begin()); return T_; } template <typename Type> Type bk(set <Type> &V_) { auto T_=*prev(V_.end()); V_.erase(*prev(V_.end())); return T_; }
mt19937 gen(time(NULL)); int rd() { return abs((int)gen()); }
int rnd(int l,int r) { return rd()%(r-l+1)+l; }
void main_init()
{
}
cint L=1.02e7,K=10;
cint z[]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};
cint M=10;
int h[L];
LL n,n2;
LL d1[M],d2[M];
pair<LL,LL> work(LL x,LL m1,LL y,LL m2)
{
// printf("begin:\n%lld,%lld %lld,%lld\n",x,m1,y,m2);
LL g=gcd(m1,m2);
if(x%g!=y%g||m1/g>n/m2) return {0ll,0ll};
LL m=m1/g*m2;
LL w1,w2; ex_gcd(w1,w2,m1/g,m2/g);
// printf("%lld*%lld+%lld*%lld=%lld\n",w1,m1,w2,m2,w1*m1+w2*m2);
LL t=(((in128)w1*m1)%m*((y-x)/g)+x)%m;
if(t<0ll) t+=m;
// printf("end\n");
return {t,m};
}
LL dfs(int m,LL w1,LL w2)
{
if(n2<w1) return 0ll;
if(!m)
{
// printf("dfs %lld,%lld\n",w1,w2);
return ((n2-w1)/w2)+(w1?1ll:0ll);
}
// printf("%lld,%lld\n",w1,w2);
LL sum=0ll;
sum+=dfs(m-1,w1,w2);
auto [w1_,w2_]=work(w1,w2,d1[m],d2[m]);
// printf("want %lld,%lld\n",w1_,w2_);
if(w2_) sum-=dfs(m-1,w1_,w2_);
return sum;
}
void main_solve()
{
LL c;
scanf("%lld%lld",&n,&c);
For_(i,1,z[7]) h[i]=h[i/10]+1;
LL ans=n/z[1]/c;
For_(i,1,z[7])
{
stop(i>=n);
int m=0;
// #define watch 12
// if(i==watch) printf("h[%d]=%d\n",i,h[i]);
For(k,1,h[i])
{
LL w1=1ll*z[h[i]-k],w2=1ll*(i/z[k]),w3=1ll*(i%z[k])+c;
// if(i==watch) printf("%lld,%lld,%lld\n",w1,w2,w3);
w1%=w3,w2=md(-w2,w3);
LL g=__gcd(w1,w3);
exc(w2%g);
w1/=g,w2/=g,w3/=g;
m++;
d1[m]=inv(w1,w3)*w2%w3,d2[m]=w3;
}
/*if(i==watch)
{
printf("i=%d\n",i);
For(k,1,m) printf("> %lld,%lld\n",d1[k],d2[k]);
}*/
n2=(n-i)/z[h[i]];
ans+=dfs(m-1,d1[m],d2[m]);
}
outll(ans);
}
int main()
{
// ios::sync_with_stdio(0); cin.tie(0);
// freopen("in.txt","r",stdin);
// freopen("out1.txt","w",stdout);
// srand(time(NULL));
main_init();
// int _; inint(_); For(__,1,_) // T>1 ?
// printf("\n------------\n\n"),
main_solve();
return 0;
}
/*
26 39
*/
詳細信息
Test #1:
score: 100
Accepted
time: 6ms
memory: 42856kb
input:
20 1
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 13ms
memory: 42900kb
input:
111 4
output:
9
result:
ok 1 number(s): "9"
Test #3:
score: 0
Accepted
time: 7ms
memory: 43560kb
input:
1111 10
output:
75
result:
ok 1 number(s): "75"
Test #4:
score: 0
Accepted
time: 475ms
memory: 42924kb
input:
1000000 7
output:
111529
result:
ok 1 number(s): "111529"
Test #5:
score: 0
Accepted
time: 13ms
memory: 42856kb
input:
1 1
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 43ms
memory: 42856kb
input:
99999 10000
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 8ms
memory: 43548kb
input:
1000 1
output:
287
result:
ok 1 number(s): "287"
Test #8:
score: 0
Accepted
time: 6241ms
memory: 42928kb
input:
10000000 1
output:
3102010
result:
ok 1 number(s): "3102010"
Test #9:
score: 0
Accepted
time: 6411ms
memory: 43192kb
input:
100000000 1
output:
31035571
result:
ok 1 number(s): "31035571"
Test #10:
score: 0
Accepted
time: 6729ms
memory: 42920kb
input:
1000000000 1
output:
310375697
result:
ok 1 number(s): "310375697"
Test #11:
score: 0
Accepted
time: 7219ms
memory: 42904kb
input:
10000000000 1
output:
3103907933
result:
ok 1 number(s): "3103907933"
Test #12:
score: 0
Accepted
time: 7860ms
memory: 43204kb
input:
100000000000 1
output:
31039265058
result:
ok 1 number(s): "31039265058"
Test #13:
score: -100
Time Limit Exceeded
input:
1000000000000 1