当前位置:网站首页>Find 3-friendly Integers
Find 3-friendly Integers
2022-07-06 16:02:00 【It's Xiao Zhang, ZSY】
Find 3-friendly Integers
link :https://ac.nowcoder.com/acm/contest/11166/F
source : Cattle from
A positive integer is 3-friendly if and only if we can find a continuous substring in its decimal representation, and the decimal integer represented by the substring is a multiple of 3.
For instance:
104 is 3-friendly because “0” is a substring of “104” and 0mod3=0.
124 is 3-friendly because “12” is a substring of “124” and 12mod3=0. “24” is also a valid substring.
17 is not 3-friendly
Note that the substring with leading zeros is also considered legal.
Given two integers L and R, you are asked to tell the number of positive integers x such that L R(L≤x≤R) and x is 3-friendly.
Input description :
There are multiple test cases. The first line of the input contains an integer T(1≤T≤10000), indicating the number of test cases. For each test case:
The only line contains two integers L,R(1≤L≤R≤10^18 ), indicating the query.
Output description :
For each test case output one line containing an integer, indicating the number of valid {x}x.
Ideas :
In fact, it is before the calculation 100 individual ,100 The numbers in the future are 3 Friendly
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll sum[105];
ll a(ll x)
{
if(x<=99)
return sum[x];
if(x>99)
{
return sum[99]+x-99;
}
}
int main()
{
for(int i=1;i<=9;i++)
{
ll cc=0;
if(i%3==0)
cc=1;
sum[i]=sum[i-1]+cc;
}
for(int i=10;i<=99;i++)
{
ll cc=0;
if(i%3==0)
{
cc=1;
}
if(i/10%3==0)
{
cc=1;
}
if(i%10%3==0)
{
cc=1;
}
sum[i]=sum[i-1]+cc;
}
int T;
cin>>T;
while(T--)
{
ll l,r;
cin>>l>>r;
cout<<a(r)-a(l-1)<<endl;
}
return 0;
}
边栏推荐
- b站 实时弹幕和历史弹幕 Protobuf 格式解析
- 信息安全-安全专业名称|CVE|RCE|POC|VUL|0DAY
- MySQL grants the user the operation permission of the specified content
- 【练习-11】4 Values whose Sum is 0(和为0的4个值)
- Common configuration files of SSM framework
- D - Function(HDU - 6546)女生赛
- MySQL授予用户指定内容的操作权限
- Opencv learning log 19 skin grinding
- mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
- If you want to apply for a programmer, your resume should be written like this [essence summary]
猜你喜欢
Pyside6 signal, slot
渗透测试 ( 1 ) --- 必备 工具、导航
mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
VS2019初步使用
[exercise-4] (UVA 11988) broken keyboard = = (linked list)
[exercise-7] crossover answers
洛谷P1102 A-B数对(二分,map,双指针)
Matlab comprehensive exercise: application in signal and system
信息安全-史诗级漏洞Log4j的漏洞机理和防范措施
【高老师UML软件建模基础】20级云班课习题答案合集
随机推荐
If you want to apply for a programmer, your resume should be written like this [essence summary]
【练习-10】 Unread Messages(未读消息)
Information security - threat detection - detailed design of NAT log access threat detection platform
STM32 how to use stlink download program: light LED running light (Library version)
Pyside6 signal, slot
Research Report on market supply and demand and strategy of China's earth drilling industry
TCP的三次握手与四次挥手
Opencv learning log 31 -- background difference
信息安全-威胁检测-flink广播流BroadcastState双流合并应用在过滤安全日志
Cost accounting [19]
Web based photo digital printing website
程序员的你,有哪些炫技的代码写法?
CEP used by Flink
【练习-7】Crossword Answers
信息安全-史诗级漏洞Log4j的漏洞机理和防范措施
China's earthwork equipment market trend report, technical dynamic innovation and market forecast
树莓派CSI/USB摄像头使用mjpg实现网页摄像头监控
Analysis of protobuf format of real-time barrage and historical barrage at station B
C语言是低级和高级的分水岭
D - Function(HDU - 6546)女生赛