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.

34 lines
748 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int c[N];
/**
* 功能获取指定数x的所有约数
* @param x
*/
void ys(int x) {
for (int i = 1; i <= sqrt(x); i++)
//有约数
if (x % i == 0) {
c[i]++; //i作为约数的次数++
//记录另一个相对的约数
//x!=i*i 防止记录重复,如果是完全平方,就记一个,这个是大的
if (x != i * i) c[x / i]++;
}
}
int main() {
int x = 120;
//获得所有的约数
ys(x);
for (int i = 1; i <= x; i++)
for (int j = 1; j <= c[i]; j++) {
cout << i;
if (i < x) cout << "*";
}
return 0;
}