代码改变世界

NB群友

2019-04-14 21:31  一只弱鸡丶  阅读(204)  评论(0)    收藏  举报

题目传送门:

看了大佬的代码才知道是这样写0.0

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define P pair<ll,ll>
#define mp make_pair
const int N=1e6+10;
const int mod=1e9+7;
void read(int &a)
{
    a=0;
    int d=1;
    char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch-'0';
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=a*10+ch-'0';
    a*=d;
}
void write(int x)
{
    if(x<0)
        putchar(45),x=-x;
    if(x>9)
        write(x/10);
    putchar(x%10+'0');
}
map <P,ll> dp;
ll dfs(ll l,ll r)
{
    if(dp.count(mp(l,r)))
        return dp[mp(l,r)];
    if(l>r)
        return 0;
    ll ans=(l==1);
    for(re int i=2;i<=9;i++)
    {
        ll now1,now2;
        now1=ceil(1.0*l/i);
        now2=r/i;
        ans=(ans+dfs(now1,now2))%mod;
    }
    return dp[mp(l,r)]=ans;
}
int main()
{
    int T;
    read(T);
    while(T--)
    {
        ll l,r;
        cin>>l>>r;
        l=l==1?2:l;
        printf("%lld\n",dfs(l,r));
    }
    return 0;
}