跳到正文

个人记录

Fuck CCF

原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年5月18日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int x,y,dp[15][3],p[50];
void pre(){
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(int i=1;i<=10;i++){
        dp[i][0]=dp[i-1][0]*9-dp[i-1][1];
        dp[i][1]=dp[i-1][0];
        dp[i][2]=dp[i-1][2]*10+dp[i-1][1]+dp[i-1][0];
    }
}
int cal(int x){
    int cnt=0,ans=0,tmp=x;
    while(x){
        p[++cnt]=x%10;
        x/=10;
    }
    bool flag=false;
    p[cnt+1]=0;
    for(int i=cnt;i>=1;i--){
        ans+=p[i]*dp[i-1][2];
        if(flag){
            ans+=p[i]*dp[i-1][0];
        }else{
            if(p[i]>4) ans+=dp[i-1][0];
            if(p[i]>6) ans+=dp[i-1][1];
            if(p[i]>2&&p[i+1]==6) ans+=dp[i][1];
            if(p[i]==4||(p[i]==2&&p[i+1]==6)) flag=true;
        }
    }
    return tmp-ans;
}
signed main(){
    pre();
    while(cin >> x >> y){
        if(!x && !y) break;
        x=min(x,y);
        y=max(x,y);
        cout << cal(y+1)-cal(x) << "\n";
    }
    return 0;
}
原文