酷代码 AI
菜单
服务商

题目描述 任给一个自然数n,求出这个自然数不同因数的个数。例如 n = 6 n=6,因为 1 , 2 , 3 , 6 1,2,3,6这四个都是6的因数,故输出 t o t a l = 4 total=4 输入 任意一个自然数n。 输出 这个自然数的因数个数。c++

```cpp #include <iostream> #include <cmath> using namespace std; int main() { int n; cin >> n; int total = 0; int sqrt_n = sqrt(n); for (int i = 1; i <= sqrt_n; i++) { if (n % i == 0) { total += 2; } } if (sqrt_n * sqrt_n == n) { total--; } cout << total << endl; return 0; } ``` [2026-01-03 14:34:19 | AI问答 | 116点数解答]

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