BZOJ 2405: 数字 数学

2405: 数字

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 281  Solved: 139
[Submit][Status][Discuss]

Description

Input

第一行一个整数T,表示数据组数。

以下每一行两个数LR(保证区间合法),代表询问[L, R]

Output

输出T行,每行一个数,表示在这个区间内小D喜欢的数出现了多少次。

你的输出当且仅当和标准输出一样才能得该测试点满分。

Sample Input

3
1 5
3 9
8 8

Sample Output

2
2
0

HINT

L,R<=10^18,T<=20


听说有大神找到了循环节??

推的式子  感觉BJ的式子不太好推

所以仅建议粘代码 不建议推BJ的式子。。。


#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

typedef unsigned long long ll;

inline ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}
void print(ll x)
{if(x<0)x=-x,putchar('-');if(x>=10)print(x/10);putchar(x%10+'0');}

inline ll getans(ll x)
{
	ll res=0;
	res+=1ll*(x+8)/9;
	res+=1ll*(x+14)/18;
	res+=1ll*(x+18)/27;
	res+=1ll*(x+20)/36;
	res+=1ll*(((x+14)/63)+1)/2;
	res+=x/81;
	ll t=1ll*(x+20)/45;
	t=t-1ll*(t/4);
	return res+t;
}

int main()
{
	ll T=read();
	while(T--)
	{
		ll l=read();ll r=read();
		print(getans(r)-getans(l-1));puts("");
	}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值