酷代码 AI
菜单
服务商

当 𝑥 最小值为多少时,可以使得 1 ∗ 1 + 2 ∗ 2 + 3 ∗ 3 + . . . + 𝑥 ∗ 𝑥 > 𝑛 ? 输入 读入一个整数 𝑛 ( 1 <= 𝑛 <= 10 9 ) 输出 输出最小的 𝑥 样例输入 复制 1 样例输出 复制 2

Python ```python n = int(input()) x = 1 total = 0 while total <= n: total += x * x x += 1 print(x - 1) ``` Pascal ```pascal program MinX; var n, x: longint; total: int64; begin readln(n); x := 1; total := 0; while total <= n do begin total := total + x * x; x := x + 1; end; writeln(x - 1); end. ``` C++ ```cpp #include <iostream> using namespace std; int main() { long long n; cin >> n; int x = 1; long long total = 0; while (total <= n) { total += x * x; x++; } cout << x - 1 << endl; return 0; } ``` C ```c #include <stdio.h> int main() { long long n; scanf("%lld", &n); int x = 1; long long total = 0; while (total <= n) { total += x * x; x++; } printf("%d\n", x - 1); return 0; } ``` Java ```java import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); long n = scanner.nextLong(); int x = 1; long total = 0; while (total <= n) { total += x * x; x++; } System.out.println(x - 1); } } ``` [2025-12-27 19:46:48 | AI问答 | 380点数解答]

相关提问
发财导航,免费问AI
实用工具查看更多