BZOJ 2405: 数字 数学

xiaoxiao2021-02-28  101

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+'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; }

转载请注明原文地址: https://www.6miu.com/read-41990.html

最新回复(0)