jzoj 2700. 数字

47 篇文章 0 订阅
27 篇文章 0 订阅

题目:

解题思路:

( n − S ( n ) )   m o d   9 = 0 (n-S(n))\ mod\ 9=0 (nS(n)) mod 9=0
∴对于每个数n, d ( n ) = ( n − 1 )   m o d   9 + 1 d(n)=(n-1)\ mod\ 9+1 d(n)=(n1) mod 9+1
然后我们就有
若小D喜欢 A = x ∗ D ( x ) A=x*D(x) A=xD(x)
则小D一定也喜欢 n + 22680 = ( x + 22680 D ( x ) ) ∗ D ( x ) n+22680=(x+\frac{22680}{D(x)})*D(x) n+22680=(x+D(x)22680)D(x)
22680 = l c m ( 1 , 2 , 3 , … … , 9 , 10 ) 22680=lcm(1,2,3,……,9,10) 22680=lcm(1,2,3,,9,10)
然后我们求出22680内的小D喜欢的数然后暴力瞎搞

Accepted code:

#include<ctime>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long

using namespace std;

const int C = 22680;
int T;
ll x, y, s[C+1];

inline ll read() {
    ll x = 0, f = 1; char c = getchar();
    while(!isdigit(c)) { if(c == '-') f = -1; c = getchar(); }
    while(isdigit(c)) x = (x<<1) + (x<<3) + c - 48,
	c = getchar(); return x * f;
}

void init() {
    T = read();
    int F;
    for (int i = 1; i <= C; i++) {
        F = i * ((i-1) % 9 + 1);
        if(F <= C) s[F] = 1;
    }
    for (int i = 1; i <= C; i++)
        s[i] += s[i-1];
}

ll cal(ll x) {
    return x/C * s[C] + s[x%C];
}

int main() {
    init();
    while(T--) {
        x = read(); y = read();
        printf("%lld\n", cal(y) - cal(x-1));
    }
    return 0;
}
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值