整数因子打表(所有因子)

#include <iostream>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <bitset>
#include <string>
#include <vector>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <functional>
#include <ctime>
#define PI acos(-1)
#define eps 1e-8
#define inf 0x3f3f3f3f
#define debug(x) cout<<"---"<<x<<"---"<<endl
typedef long long ll;
using namespace std;
 
int YZ[100000] , yzs;
void DB(int now)
{
    yzs = 0;
    int maxx = (int)sqrt(now);
    for (int i = 1 ; i <= maxx ; i ++)
    {
        if (now % i == 0)
        {
            YZ[++yzs] = i;
            YZ[++yzs] = now / i;
        }
    }
    if (maxx * maxx == now)
    {
        yzs --;
    }
}
int main()
{
    int n;
    while (cin >> n)
    {
        DB(n);
        sort(YZ + 1 , YZ + yzs + 1);
        for (int i = 1; i <= yzs; i++)
        {
            cout << YZ[i] << endl;
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sodacoco/article/details/81610338