跳到正文

题解

勾股定理题解

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

文章信息

发布
2025年2月21日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 1 分钟

版本

  1. v1当前

思路

简单枚举,但是数据很大,怎么办呢,没关系,其实这个题只需要枚举到sqrt(c)即可

代码

C++
#include<bits/stdc++.h>
using namespace std;
int main() {
	freopen("theorem.in","r",stdin);
	freopen("theorem.out","w",stdout);
    int ans=0,c;
    cin >> c;
    for(int i=1;i<sqrt(c);i++){
    	for(int j=1;j<sqrt(c);j++){
    		if((i*i+j*j)<c) ans++;
		}
	}
	cout << ans;
}

复杂度就降低到sqrt(c)∗sqrt(c)sqrt(c)*sqrt(c)了!

原文