当前位置:网站首页>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;
}
边栏推荐
- Information security - threat detection - Flink broadcast stream broadcaststate dual stream merging application in filtering security logs
- D - Function(HDU - 6546)女生赛
- F - Birthday Cake(山东省赛)
- Opencv learning log 14 - count the number of coins in the picture (regardless of overlap)
- Nodejs crawler
- Record of brushing questions with force deduction -- complete knapsack problem (I)
- Shell脚本编程
- 【练习4-1】Cake Distribution(分配蛋糕)
- Cost accounting [15]
- Cost accounting [22]
猜你喜欢

Optimization method of path problem before dynamic planning

STM32 learning record: LED light flashes (register version)

滲透測試 ( 1 ) --- 必備 工具、導航

Web based photo digital printing website

Analysis of protobuf format of real-time barrage and historical barrage at station B

Determine the Photo Position
![[exercise-4] (UVA 11988) broken keyboard = = (linked list)](/img/59/78ca7170ab1fd364ec44cfbcdc7ab5.png)
[exercise-4] (UVA 11988) broken keyboard = = (linked list)

Ball Dropping
![[exercise-7] crossover answers](/img/66/3dcba2e70a4cd899fbd78ce4d5bea2.png)
[exercise-7] crossover answers

【高老师UML软件建模基础】20级云班课习题答案合集
随机推荐
【练习4-1】Cake Distribution(分配蛋糕)
Nodejs+vue网上鲜花店销售信息系统express+mysql
STM32 how to use stlink download program: light LED running light (Library version)
Penetration test (1) -- necessary tools, navigation
China chart recorder market trend report, technology dynamic innovation and market forecast
Cost accounting [16]
MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’
[exercise-7] crossover answers
洛谷P1102 A-B数对(二分,map,双指针)
[exercise-2] (UVA 712) s-trees
D - Function(HDU - 6546)女生赛
Record of brushing questions with force deduction -- complete knapsack problem (I)
[exercise-1] (UVA 673) parentheses balance/ balanced brackets (stack)
【练习-8】(Uva 246)10-20-30==模拟
信息安全-安全专业名称|CVE|RCE|POC|VUL|0DAY
[analysis of teacher Gao's software needs] collection of exercises and answers for level 20 cloud class
Research Report on market supply and demand and strategy of geosynthetics industry in China
E. Breaking the Wall
Web based photo digital printing website
【练习-4】(Uva 11988)Broken Keyboard(破损的键盘) ==(链表)