2021牛客暑期多校训练营1Find 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 333.

For instance:

  1.  104{104}104 is 3-friendly because "0" is a substring of "104" and 0mod  3=00 \mod 3 = 00mod3=0.
  2.  124{124}124 is 3-friendly because "12" is a substring of "124" and 12mod  3=012 \mod 3 = 012mod3=0. "24" is also a valid substring.
  3.  17{17}17 is not 3-friendly because 1mod  3≠0, 7mod  3≠0, 17mod  3≠01 \mod 3 \ne 0, ~7 \mod 3 \ne 0, ~17 \mod 3 \ne 01mod3​=0, 7mod3​=0, 17mod3​=0.


Note that the substring with leading zeros is also considered legal.

Given two integers L{L}L and R{R}R, you are asked to tell the number of positive integers x{x}x such that L≤x≤RL \le x \le RL≤x≤R and x{x}x is 3-friendly.

输入描述:

There are multiple test cases. The first line of the input contains an integer T(1≤T≤10000)T(1 \le T \le 10000)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≤1018)L,R(1 \le L \le R \le 10^{18})L,R(1≤L≤R≤1018), indicating the query.

输出描述:

For each test case output one line containing an integer, indicating the number of valid x{x}x.

示例1

输入

3
4 10
1 20
1 100

输出

3
11
76

这题

题意是说找出有3的数有多少个

可以是单独的3的倍数

也可以是前几位数是3的倍数

是三的倍数的话就是相加为3

所以超过100的数都是满足条件的

在100以内的数都用打表表示出来了

要考虑边缘

边缘的考虑耐心点就行了

#include<iostream>
using namespace std;
int main()
{
	int t;
	cin>>t;
	long long n,m;
	int a[91]={0,0,0,1,1,1,2,2,2,3,4,4,5,6,6,7,8,8,9,10,11,12,12,13,14,14,15,16,16,17,18,19,20,21,22,23,24,25,26,27,28,28,29,30,30,31,32,32,33,34,35,36,36,37,38,38,39,40,40,41,42,43,44,45,46,47,48,49,50,51,52,52,53,54,54,55,56,56,57,58,59,60,60,61,62,62,63,64,64,65,66};
	//cout<<a[89]<<endl;
	while(t--)
	{
		cin>>n>>m;
		int p=0,q=0;
		if(n>=90&&m>=90)
		{
			cout<<m-n+1<<endl;
		}
		else if(n<90&&m>=90)
		{
			if(a[n]==a[n-1])
			p=1;
			if(a[m]==a[m-1])
			q=1;
			if(m==90&&p==0)
			cout<<m-90+1+a[89]-a[n]+1<<endl;
			else if(m==90&&p==1)
			{
				cout<<m-90+a[89]-a[n]+1<<endl;
			}
			else if(m!=90&&p==0)
			cout<<m-90+1+a[89]-a[n]+1<<endl;
			else
			cout<<m-90+a[89]-a[n]+1<<endl;
		}
		else if(m<90)
		{
			if(a[n]==a[n-1])
			p=1;
			if(a[m]==a[m-1])
			q=1;
			if(p==1&&q==1)
			cout<<a[m]-a[n]<<endl;
			else
			if(p==1&&q==0)
			cout<<a[m]-a[n]<<endl;
			else if(p==0&&q==1)
			cout<<a[m]-a[n]+1<<endl;
			else
			cout<<a[m]-a[n]+1<<endl;
		}
	}
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值