对于这道题,我简直无话可说。。。
一开始,我准备枚举,但当看到那神奇的数据范围时,便灵光乍现突然明白,这是不可能的。(相信大家都不想TLE)
所以,我以一种天才的预感开始了分类讨论。(看到许多dalao都在做数学题,很遗憾,鄙人不才,只能做这种低级的工作)
n=1 n=2 n=3 n=4 n=5 n=6 n=7 n=8 n=9 n=10…
输出则是:1,1,1,1 4,1 4,1 4,1 4,1 4,1 4 9,1 4 9…
于是,我明白了规律。答案是1到n的平方根(取整)的平方,即1,4,9,…,sqrt(n)×sqrt(n)。这是一道典型水题。 废话不多说,下面粘代码:
#include<bits/stdc++.h> //万能头
using namespace std;
long long int n; //数据太大,开long long int
int main()
{
cin>>n;
for(long long int i=1;i<=sqrt(n);i++)//注意是sqrt
{
cout<<i*i<<" ";//输出i的平方
}
return 0;
}