(题目链接:https://www.luogu.com.cn/problem/P1876)


#include<bits/stdc++.h>
using namespace std;
long long n;
int main()
{
scanf("%lld",&n);
for(long long i=1;i*i<=n;i++)printf("%lld ",i*i);
return 0;
}
本文解析了洛谷编程题P1876的解决方案,通过C++代码实现了一个程序,该程序能够计算并输出所有小于等于输入整数n的平方数。通过对代码的逐行解释,读者可以理解如何使用for循环和条件判断来解决此类数学问题。
(题目链接:https://www.luogu.com.cn/problem/P1876)


#include<bits/stdc++.h>
using namespace std;
long long n;
int main()
{
scanf("%lld",&n);
for(long long i=1;i*i<=n;i++)printf("%lld ",i*i);
return 0;
}
640
355

被折叠的 条评论
为什么被折叠?