这题占坑备用(搜索)

Problem Description

ACdream王国的大数学家NT(Number Theory),发现了一种独特的数,称之为NT数,其定义如下:
1. 长度为1的数都是NT数。
2.对于一个长度大于1的数,当且仅当他能被长度整除,且商为NT数,那么这个数也是NT数。
NT相信这样的数是无穷无尽的!然而他还是想知道在一个区间内这样的数有多少个。
Input

多组数据(大约1000组),每组数据包括两个整数L,R(0<=L

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
vector<ll>gather;
ll bit(ll x)
{
    ll ans = 0;
    while(x != 0)
    {
        ans++;x /= 10;
    }
    return ans;
}
void check(ll x)
{
    for(ll i = 2;i <= 18;i++)
    {
        if(bit(i*x) == i)
        {
            gather.push_back(i*x);
            check(i*x);
        }
    }
}
void init()
{
    for(int i = 0;i <= 9;i++)gather.push_back(i);
    for(ll i = 5;i <= 9;i++)
        check(i);
}
int main()
{
    #ifdef LOCAL
    freopen("C:\\Users\\ΡΡ\\Desktop\\in.txt","r",stdin);
    //freopen("C:\\Users\\ΡΡ\\Desktop\\out.txt","w",stdout);
    #endif // LOCAL
    init();
    ll l,r;
    sort(gather.begin(),gather.end());
    while(scanf("%lld%lld",&l,&r) != EOF)
    {
        ll ans = lower_bound(gather.begin(),gather.end(),r) - lower_bound(gather.begin(),gather.end(),l);
        printf("%lld\n",ans);
    }
    return 0;
}

事实证明,条件范围内只有301个这样的数。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值