当前位置:网站首页>Find 3-friendly Integers
Find 3-friendly Integers
2022-07-06 09:25:00 【是小张张呀 zsy】
Find 3-friendly Integers
链接:https://ac.nowcoder.com/acm/contest/11166/F
来源:牛客网
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.
输入描述:
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.
输出描述:
For each test case output one line containing an integer, indicating the number of valid {x}x.
思路:
其实就是算出前100个,100以后的数都是3的友好型
#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;
}
边栏推荐
- JS --- all knowledge of JS objects and built-in objects (III)
- Accounting regulations and professional ethics [3]
- 学习记录:使用STM32外部输入中断
- Alice and Bob (2021牛客暑期多校训练营1)
- The most detailed postman interface test tutorial in the whole network. An article meets your needs
- Market trend report, technical innovation and market forecast of lip care products in China and Indonesia
- Research Report of pharmaceutical solvent industry - market status analysis and development prospect prediction
- Research Report on market supply and demand and strategy of China's Medical Automation Industry
- csapp shell lab
- C4D quick start tutorial - creating models
猜你喜欢
C语言学习笔记
学习记录:USART—串口通讯
ucore lab 2
Eslint--- error: newline required at end of file but not found (EOL last) solution
Learning record: how to perform PWM output
csapp shell lab
Crawler series of learning while tapping (3): URL de duplication strategy and Implementation
程序员的你,有哪些炫技的代码写法?
Leetcode notes - dynamic planning -day6
C语言是低级和高级的分水岭
随机推荐
Report on the market trend, technological innovation and market forecast of printing and decorative paper in China
洛谷P1102 A-B数对(二分,map,双指针)
Market trend report, technological innovation and market forecast of pneumonia drugs obtained by Chinese hospitals
Eslint--- error: newline required at end of file but not found (EOL last) solution
Research Report on market supply and demand and strategy of geosynthetics industry in China
JS --- detailed explanation of JS facing objects (VI)
ucore lab5
Cost accounting [17]
JS --- all basic knowledge of JS (I)
Flex --- detailed explanation of flex layout attributes
入门C语言基础问答
Research Report on medical anesthesia machine industry - market status analysis and development prospect prediction
Research Report on market supply and demand and strategy of China's medical chair industry
STM32学习记录:输入捕获应用
Research Report on printed circuit board (PCB) connector industry - market status analysis and development prospect forecast
Es6--- two methods of capturing promise status as failed
Winter vacation daily question - maximum number of balloons
Research Report on medical toilet industry - market status analysis and development prospect forecast
Research Report on market supply and demand and strategy of China's land incineration plant industry
JS --- JS function and scope (II)