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个这样的数。