QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#507939#9139. Prefix Divisible by SuffixXY_ElevenAC ✓1671ms8116kbC++235.7kb2024-08-07 00:14:482024-08-07 00:14:48

Judging History

你现在查看的是最新测评结果

  • [2024-08-07 00:14:48]
  • 评测
  • 测评结果:AC
  • 用时:1671ms
  • 内存:8116kb
  • [2024-08-07 00:14:48]
  • 提交

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.02e6,K=10;
cint z[]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};
cint M=10;
int h[L];
LL n,n2,c;
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;
}
bool check(LL w)
{
    // printf("w=%lld\n",w);
    For(i,1,6) if(!((w/z[i])%(w%z[i]+c)))
        return false;
    return true;
}
void main_solve()
{
    scanf("%lld%lld",&n,&c);
    For_(i,1,z[6]) h[i]=h[i/10]+1;
    LL ans=n/z[1]/c;
    For_(i,1,z[6])
    {
        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]);
    }
    For_(i,z[6],z[7])
    {
        int up=(int)(max(n-i,0ll)/z[7]),i2=i+(int)c;
        // printf("up=%d\n",up);
        for(int j=i2;j<=up;j+=i2)
            if(check(1ll*j*z[7]+i))
                ans++;
    }
    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
*/

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 7772kb

input:

20 1

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 12ms
memory: 8004kb

input:

111 4

output:

9

result:

ok 1 number(s): "9"

Test #3:

score: 0
Accepted
time: 9ms
memory: 7776kb

input:

1111 10

output:

75

result:

ok 1 number(s): "75"

Test #4:

score: 0
Accepted
time: 490ms
memory: 7776kb

input:

1000000 7

output:

111529

result:

ok 1 number(s): "111529"

Test #5:

score: 0
Accepted
time: 8ms
memory: 8116kb

input:

1 1

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 54ms
memory: 8048kb

input:

99999 10000

output:

0

result:

ok 1 number(s): "0"

Test #7:

score: 0
Accepted
time: 9ms
memory: 7748kb

input:

1000 1

output:

287

result:

ok 1 number(s): "287"

Test #8:

score: 0
Accepted
time: 500ms
memory: 7772kb

input:

10000000 1

output:

3102010

result:

ok 1 number(s): "3102010"

Test #9:

score: 0
Accepted
time: 532ms
memory: 7752kb

input:

100000000 1

output:

31035571

result:

ok 1 number(s): "31035571"

Test #10:

score: 0
Accepted
time: 575ms
memory: 8008kb

input:

1000000000 1

output:

310375697

result:

ok 1 number(s): "310375697"

Test #11:

score: 0
Accepted
time: 633ms
memory: 7844kb

input:

10000000000 1

output:

3103907933

result:

ok 1 number(s): "3103907933"

Test #12:

score: 0
Accepted
time: 678ms
memory: 7824kb

input:

100000000000 1

output:

31039265058

result:

ok 1 number(s): "31039265058"

Test #13:

score: 0
Accepted
time: 684ms
memory: 7748kb

input:

1000000000000 1

output:

310394177863

result:

ok 1 number(s): "310394177863"

Test #14:

score: 0
Accepted
time: 727ms
memory: 7752kb

input:

10000000000000 1

output:

3103943538348

result:

ok 1 number(s): "3103943538348"

Test #15:

score: 0
Accepted
time: 1270ms
memory: 7848kb

input:

100000000000000 1

output:

31039449626535

result:

ok 1 number(s): "31039449626535"

Test #16:

score: 0
Accepted
time: 1438ms
memory: 7704kb

input:

100000000000000 10

output:

9041696367054

result:

ok 1 number(s): "9041696367054"

Test #17:

score: 0
Accepted
time: 1586ms
memory: 7752kb

input:

100000000000000 100

output:

1744469671929

result:

ok 1 number(s): "1744469671929"

Test #18:

score: 0
Accepted
time: 1669ms
memory: 8032kb

input:

100000000000000 1000

output:

263959224215

result:

ok 1 number(s): "263959224215"

Test #19:

score: 0
Accepted
time: 1665ms
memory: 7836kb

input:

100000000000000 10000

output:

35400402243

result:

ok 1 number(s): "35400402243"

Test #20:

score: 0
Accepted
time: 1625ms
memory: 7776kb

input:

100000000000000 239

output:

870346971377

result:

ok 1 number(s): "870346971377"

Test #21:

score: 0
Accepted
time: 1582ms
memory: 8036kb

input:

99999987654321 111

output:

1606282527743

result:

ok 1 number(s): "1606282527743"

Test #22:

score: 0
Accepted
time: 1671ms
memory: 7832kb

input:

96709210826727 9568

output:

35605797003

result:

ok 1 number(s): "35605797003"

Test #23:

score: 0
Accepted
time: 1088ms
memory: 7840kb

input:

22952388910151 8412

output:

9470863043

result:

ok 1 number(s): "9470863043"

Test #24:

score: 0
Accepted
time: 1243ms
memory: 7680kb

input:

49191272026279 3065

output:

49381052989

result:

ok 1 number(s): "49381052989"

Test #25:

score: 0
Accepted
time: 1498ms
memory: 8064kb

input:

75434450109703 9205

output:

28741533023

result:

ok 1 number(s): "28741533023"

Test #26:

score: 0
Accepted
time: 897ms
memory: 8004kb

input:

1677628193127 753

output:

5631822336

result:

ok 1 number(s): "5631822336"

Test #27:

score: 0
Accepted
time: 649ms
memory: 7772kb

input:

1000010000 10000

output:

328824

result:

ok 1 number(s): "328824"

Extra Test:

score: 0
Extra Test Passed