QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#361242#7954. Special NumbersSolitaryDreamWA 12ms172196kbC++171.5kb2024-03-23 00:54:282024-03-23 00:54:28

Judging History

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

  • [2024-03-23 00:54:28]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:172196kb
  • [2024-03-23 00:54:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define int long long

const int P=1e9+7;

int f[22][2][2][22][22][22][23];

string l,r;

int k;

__int128 pw[11][21];

int dp(int x,int lead,int dw,int up,int c2,int c3,int c5,int c7)
{
    if(x==r.size())
    {
        if(c7==22)
            return 1;
        __int128 w=pw[2][c2]%k*pw[3][c3]%k*pw[5][c5]%k*pw[7][c7]%k;
        return !w;
    }
    if(f[x][lead][up][c2][c3][c5][c7]!=-1)
        return f[x][lead][up][c2][c3][c5][c7];
    int &ret=f[x][lead][up][c2][c3][c5][c7];
    ret=0;
    for(int i=(dw?l[x]-'0':0);i<=(up?r[x]-'0':9);i++)
    {
        int w=i;
        int nlead=lead&&i==0;
        int ndw=dw&&i==l[x]-'0';
        int nup=up&&i==r[x]-'0';
        int nc2=c2,nc3=c3,nc5=c5,nc7=c7;
        if(!nlead)
        {
            if(!w)
                nc2=nc3=nc5=nc7=22;
            else
            {
                while(w%2==0)
                    nc2++,w/=2;
                while(w%3==0)
                    nc3++,w/=3;
                while(w%5==0)
                    nc5++,w/=5;
                while(w%7==0)
                    nc7++,w/=7;
            }
        }
        ret+=dp(x+1,nlead,ndw,nup,nc2,nc3,nc5,nc7);
    }
    return ret%=P;
}

signed main()
{
    cin>>k>>l>>r;
    while(l.size()<r.size())
        l='0'+l;
    for(int i=1;i<=9;i++)
    {
        pw[i][0]=1;
        for(int j=1;j<=20;j++)
            pw[i][j]=pw[i][j-1]*i;
    }
    memset(f,-1,sizeof(f));
    cout<<dp(0,1,1,1,0,0,0,0)<<"\n";
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 172148kb

input:

5 1 20

output:

4

result:

ok single line: '4'

Test #2:

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

input:

5 50 100

output:

19

result:

ok single line: '19'

Test #3:

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

input:

15 11 19

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 4ms
memory: 171904kb

input:

1 100 100000

output:

99901

result:

ok single line: '99901'

Test #5:

score: 0
Accepted
time: 3ms
memory: 171940kb

input:

1 1 1

output:

1

result:

ok single line: '1'

Test #6:

score: -100
Wrong Answer
time: 3ms
memory: 171944kb

input:

10 800 43021

output:

21564

result:

wrong answer 1st lines differ - expected: '23570', found: '21564'