You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
648 B
29 lines
648 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
|
|
//找出n的所有约数
|
|
const int N = 1010;
|
|
int a[N]; //哪些约数
|
|
int idx; //共多少个
|
|
void find_divisors(int n) {
|
|
for (int i = 1; i <= n / i; i++)
|
|
if (n % i == 0) {
|
|
a[++idx] = i;
|
|
//防止出现5*5这样的录入两次
|
|
if (i != n / i)a[++idx] = n / i;
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
//找一下
|
|
find_divisors(120);
|
|
//输出个数
|
|
cout << idx << endl;
|
|
//输出是哪些
|
|
sort(a + 1, a + 1 + idx);
|
|
for (int i = 1; i <= idx; i++) cout << a[i] << " ";
|
|
cout << endl;
|
|
return 0;
|
|
} |