3257. 七减一

10175101159

突然翻到中二时期写的代码
全程复制黏贴+肉眼调斜率23333

if(n%10>6)++s;
        if(n%100>60)n%100<71?s+=n%100-60:s+=10;
        if(n%1000>600)n%1000<701?s+=n%1000-600:s+=100;
        if(n%10000>6000)n%10000<7001?s+=n%10000-6000:s+=1000;
        if(n%100000>60000)n%100000<70001?s+=n%100000-60000:s+=10000;
        if(n%1000000>600000)n%1000000<700001?s+=n%1000000-600000:s+=100000;
        if(n%10000000>6000000)n%10000000<7000001?s+=n%10000000-6000000:s+=1000000;
        if(n%100000000>60000000)n%100000000<70000001?s+=n%100000000-60000000:s+=10000000;
        if(n%1000000000>600000000)n%1000000000<700000001?s+=n%1000000000-600000000:s+=100000000;
        if(n%10000000000>6000000000)n%10000000000<7000000001?s+=n%10000000000-6000000000:s+=1000000000;
        if(n%100000000000>60000000000)n%100000000000<70000000001?s+=n%100000000000-60000000000:s+=10000000000;
        if(n%1000000000000>600000000000)n%1000000000000<700000000001?s+=n%1000000000000-600000000000:s+=100000000000;
        if(n%10000000000000>6000000000000)n%10000000000000<7000000000001?s+=n%10000000000000-6000000000000:s+=1000000000000;
        if(n%100000000000000>60000000000000)n%100000000000000<70000000000001?s+=n%100000000000000-60000000000000:s+=10000000000000;
        if(n%1000000000000000>600000000000000)n%1000000000000000<700000000000001?s+=n%1000000000000000-600000000000000:s+=100000000000000;
        if(n%10000000000000000>6000000000000000)n%10000000000000000<7000000000000001?s+=n%10000000000000000-6000000000000000:s+=1000000000000000;
        if(n%100000000000000000>60000000000000000)n%100000000000000000<70000000000000001?s+=n%100000000000000000-60000000000000000:s+=10000000000000000;
        if(n%1000000000000000000>600000000000000000)n%1000000000000000000<700000000000000001?s+=n%1000000000000000000-600000000000000000:s+=100000000000000000;
yuanfang

参考文章:https://blog.csdn.net/wust_zzwh/article/details/52100392

#include <cstring>
#include <iostream>
using namespace std;
int num[20];
long long dp[20][20];
long long dfs(int pos, int sum, bool limit) {
    if (pos == -1) {
        return sum;
    }
    if (!limit && dp[pos][sum] != -1) {
        return dp[pos][sum];
    }
    long long ans = 0;
    int up = limit ? num[pos] : 9;
    for (int i = 0; i <= up; ++i) {
        ans += dfs(pos - 1, sum + (i == 6), limit && (i == num[pos]));
    }
    if (!limit) {
        dp[pos][sum] = ans;
    }
    return ans;
}
long long solve(long long x) {
    int pos = 0;
    while (x != 0) {
        num[pos++] = x % 10;
        x /= 10;
    }
    return dfs(pos - 1, 0, true);
}
int main() {
    long long l, r;
    while (cin >> l >> r) {
        memset(dp, -1, sizeof(dp));
        cout << solve(r) - solve(l - 1) << endl;
    }
    return 0;
}
SmallY

数学题

def pre(x):
    six = 0
    x //= 10
    while x != 0:
        if x%10 == 6:
            six += 1
        x //= 10
    return six

def f(x):
    res = 0 if x%10 < 6 else 1
    if x < 10:
        return res
    res += x//10 + (x%10+1) * pre(x)
    return res + 10*f(x//10-1)

while True:
    try:
        l, r = map(int, input().split())
        print(f(r)-f(l-1))
    except:
        break
你当前正在回复 博客/题目
存在问题!