题解 | B=A×A

B=A×A

https://www.nowcoder.com/practice/21132ecf432b45a5a8187ea074a5d71e

#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int T;
    cin >> T;
    while (T--) {
        long long x;
        cin >> x;

        long long res = sqrt(x);

        // 也是现在明白,sqrt函数对象如果太大的话会带来很大的误差,因为sqrt函数返回值类型是浮点数嘛,所以我们要保障它符合题目要求:res*res<=x,所以这就是ACCODE,感谢您愿意花时间看我的题解,谢谢。
        while (res * res > x) res--;  // 如果太大就减小

        cout << res << endl;
    }
    return 0;
}

全部评论
好解兄弟好解
点赞 回复 分享
发布于 2025-12-19 16:17 湖南

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务