和毒老鼠问题几乎一样。用dp做。求最小次数很容易,策略数用前缀和做,比较坑的是C++的取模不支持负数。
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define ms(arr,a) memset(arr,a,sizeof arr)
#define debug(x) cout<<"< "#x" = "<<x<<" >"<<endl
const int mod=1e8+73;
const int maxn=5e6+5;
int s[maxn]={0,1,3};
inline int f(int n)
{
return n*(n+1)/2;
}
inline int invf(int x)
{
return ceil(-0.5+sqrt(2*x+0.25));
}
int main()
{
for(int i=3;i<maxn;++i)
{
s[i]=(s[i-1]+s[f(invf(i)-1)]-s[i-invf(i)-1]+mod)%mod;
}
int a,b;
while(~scanf("%d%d",&a,&b))
{
int n=b-a+1;
printf("%d %d
",invf(n),(s[n]-s[n-1]+mod)%mod);
}
}