当前位置:网站首页>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;
}
边栏推荐
- 渗透测试 ( 5 ) --- 扫描之王 nmap、渗透测试工具实战技巧合集
- [exercise-7] (UVA 10976) fractions again?! (fraction split)
- [exercise-5] (UVA 839) not so mobile (balance)
- Opencv learning log 33 Gaussian mean filtering
- 【练习-6】(PTA)分而治之
- 想应聘程序员,您的简历就该这样写【精华总结】
- Research Report on market supply and demand and strategy of China's land incineration plant industry
- Cost accounting [19]
- Information security - threat detection - Flink broadcast stream broadcaststate dual stream merging application in filtering security logs
- 【练习-9】Zombie’s Treasure Chest
猜你喜欢

用C语言写网页游戏

信息安全-威胁检测引擎-常见规则引擎底座性能比较
![[exercise-4] (UVA 11988) broken keyboard = = (linked list)](/img/59/78ca7170ab1fd364ec44cfbcdc7ab5.png)
[exercise-4] (UVA 11988) broken keyboard = = (linked list)

渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具
![[analysis of teacher Gao's software needs] collection of exercises and answers for level 20 cloud class](/img/3b/dc43564a36f82e73826b08f39c935e.png)
[analysis of teacher Gao's software needs] collection of exercises and answers for level 20 cloud class
快速转 TypeScript 指南

Ball Dropping

信息安全-威胁检测-NAT日志接入威胁检测平台详细设计

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

1010 things that college students majoring in it must do before graduation
随机推荐
[exercise-4] (UVA 11988) broken keyboard = = (linked list)
Research Report on surgical fluid treatment industry - market status analysis and development prospect prediction
China earth moving machinery market trend report, technical dynamic innovation and market forecast
入门C语言基础问答
0-1背包问题(一)
MySQL grants the user the operation permission of the specified content
编程到底难在哪里?
X-forwarded-for details, how to get the client IP
New to redis
HDU - 6024 Building Shops(女生赛)
渗透测试 2 --- XSS、CSRF、文件上传、文件包含、反序列化漏洞
D - Function(HDU - 6546)女生赛
Opencv learning log 18 Canny operator
nodejs爬虫
STM32 how to use stlink download program: light LED running light (Library version)
Research Report of exterior wall insulation system (ewis) industry - market status analysis and development prospect prediction
[exercise-6] (PTA) divide and conquer
渗透测试 ( 4 ) --- Meterpreter 命令详解
[exercise-8] (UVA 246) 10-20-30== simulation
China's peripheral catheter market trend report, technological innovation and market forecast