首页 > 试题广场 >

平方根

[编程题]平方根
  • 热度指数:28710 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
\hspace{15pt}给定一个正整数 n,求 \sqrt{n} 的整数部分,即对 \sqrt{n} 向下取整的结果。

\hspace{15pt}例如,\sqrt{5}=2.236\ldots 向下取整后为 2\sqrt{16}=4.000\ldots 向下取整后为 4

输入描述:
\hspace{15pt}在一行中输入一个整数 n \left(1 \leqq n \leqq 10^9\right)


输出描述:
\hspace{15pt}输出一个整数,表示 \sqrt{n} 向下取整后的值。
示例1

输入

5

输出

2

说明

\sqrt{5}\approx2.236,向下取整后为 2
示例2

输入

16

输出

4

说明

\sqrt{16}=4.000,向下取整后为 4
头像 我是一只小肚肚
发表于 2021-02-21 09:29:49
奈何本人的知识储备有限,就采取了循环;见谅 int main() { int n, i; scanf("%d", &n); for (i = 1;i <= n; i++) { if((i*i)>n) { 展开全文
头像 张田懿
发表于 2020-12-12 12:56:09
include<bits/stdc++.h> int main(){ int n,sq=0; scanf("%d",&n); sq=floor(sqrt(n)); printf("%d",sq); return 0;}
头像 一名蒟蒻
发表于 2023-10-19 17:13:52
方法一: ```// 牛顿送代法 #include<bits/stdc++.h> using namespace std; int n; double f( int m ) { double last = m; double ans = m; ans = ( ans + m 展开全文
头像 麻花蘸豆浆
发表于 2020-02-08 16:44:30
include<stdio.h> include<math.h> main(){int n,m; scanf("%d",&n);m=sqrt(n); //整形数据间的运算本身就包含向下取整printf("%d",m);}
头像 为我弹首琴吧
发表于 2023-12-17 16:42:03
#include<stdio.h> #include<math.h> int main() {     int n,t;     scanf("%d",&n);     t=sqrt(n);   & 展开全文
头像 柳乐
发表于 2025-07-08 17:44:59
n = int(input()) import math print(int(math.sqrt(n)))
头像 天元之弈
发表于 2022-01-16 15:19:33
原题传送门->https://ac.nowcoder.com/acm/problem/22003 my blog->https://blog.nowcoder.net/yanhaoyang2106?page=2 题目描述 输入一个整数, 求它的平方根,输出答案往下取整. 输入描述: 输入 展开全文
头像 CARLJOSEPHLEE
发表于 2025-07-15 20:20:05
print(int(int(input())**0.5))
头像 牛客671368301号
发表于 2025-08-19 16:20:47
a = int(input()) c = int(a**0.5) print(c)
头像 潍坊鲨鱼公园儿童大学
发表于 2021-01-23 08:57:08
#include <cmath> #include <iostream> using namespace std; int main() { double num; cin >> num; double root = sqrt(num) 展开全文