vector<int> get_divisors(int x){ vector<int> res; for (int i = 1; i <= x / i; i ++ ){ // 约数从1开始枚举 if (x % i == 0){ res.push_back(i); if (i != x / i) res.push_back(x / i); } } sort(res.begin(),res.end()); return res; }
intmain(){ int n,x; cin >> n; while (n -- ){ cin >> x; auto res = get_divisors(x); for (int &it:res) cout << it << ' '; cout << '\n'; } return0; }
#include<iostream> #include<algorithm> #include<unordered_map> typedeflonglong LL; usingnamespacestd; constint MOD = 1e9 + 7; int n;
intmain(){ cin >> n; int x; // primes下标会很大,用vector不合适,需要哈希表 unordered_map<int,int> primes; while (n -- ){ cin >> x; for (int i = 2;i <= x / i;i ++){ while (x % i == 0){ primes[i]++; x /= i; } } if (x != 1) primes[x]++; } LL res = 1; // 从1开始乘,不是0 for (auto it : primes) res = res * (it.second + 1) % MOD; cout << res << '\n'; return0; }
#include<iostream> #include<algorithm> #include<unordered_map> typedeflonglong LL; usingnamespacestd; constint MOD = 1e9+7; int n;
intmain(){ cin >> n; int x; unordered_map<int,int> hash; while (n -- ){ cin >> x; for (int i = 2; i <= x/i; i ++ ){ while (x % i == 0){ x /= i,hash[i]++; } } if (x > 1) hash[x]++; } LL res = 1; for (auto prime : hash){ LL t = 1,a = prime.first,b = prime.second; while (b--) t = (t*a + 1) % MOD; res = (res * t) % MOD; } cout << res << '\n'; return0; }