跳到正文

题解

题解:AT_abc428_d [ABC428D] 183184

adnap_约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年10月19日
收录
2026年9月13日
更新
2026年9月13日
篇幅
约 2 分钟

版本

  1. v1当前

题目分析

注意到题目要求的的是c(c+1)‾至cd‾\overline{c(c+1)}至\overline{cd} 之间的完全平方数数量

注意

这里有一个魔鬼细节,在上述范围中,只有开头为cc的才可以。

整理

即要求我们求一下有多少个在c(c+1)‾≤x≤cd‾\overline{c(c+1)}≤x≤\overline{cd}(xx是完全平方数)

思路

枚举位数,且满足开头为cc的,可以O(18)O(18)的求出答案,整体复杂度O(18T)O(18T)

代码

C++
#include<bits/stdc++.h>
#define int long long
//不开__,见___
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin>>T;
	while(T--)
	{
        //多组数据
		int c,d;
		cin>>c>>d;
		int ans=0;
		for(int i=10;;i*=10)
		{
            //枚举位数
			int l=i/10-c,r=i-1-c;
      //上下界
			if(l<1) l=1;
			if(r<1) continue;
			if(l>d) break;
			if(r>d)r=d;
			int _=c*i+c+l-1,__=c*i+c+r;
			ans+=floor(sqrtl(__))-floor(sqrtl(_));//一定是floor
		}
		cout<<ans<<endl;
	}
	return 114514;//防伪
}
原文