跳到正文

题解

题解:P14304 【MX-J27-T1】分块

Wh_Dawn约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年10月25日
收录
2026年10月23日
更新
2026年11月3日
篇幅
约 1 分钟
题目
P14304

版本

  1. v1当前

思路

将当前数开根,在其前的每个正整数都有三个对应的数。

例如:

11、22、33 有因数 11;

44、66、88 有因数 22;

99、1212、1515 有因数 33;

1616、2020、2424 有因数 44。

因此每个因数都对应 33 个正整数。

代码

C++
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T&x){
x=0;char c;int sign=1;
do{c=getchar();if(c=='-') sign=-1;} while(!isdigit(c));
do{x=x*10+c-'0';c=getchar();}while(isdigit(c));
x*=sign;
}
long long t,n,x,y,z,ans;
int main()
{
	read(t);
	while(t--)
	{
		read(n);
		x=sqrt(n);
		ans=(x-1)*3;
		if(x*x==n) ans+=1;
		else 
		{
			y=x+1,z=x+2;
			if(x*x<=n) ans+=1;
			if(x*y<=n) ans+=1;
			if(x*z<=n) ans+=1;
		}
		cout<<ans<<'\n';
	}
	return 0;
}
原文