fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. const int MOD = 1e9+7;
  5.  
  6. const int MAXN = 1e6;
  7. vector<int> spf(MAXN + 1, 0);
  8.  
  9. void computeSpf(){
  10. for (int i = 2; i <= MAXN; i++){
  11. spf[i] = i;
  12. }
  13.  
  14. // starting the sieve process
  15.  
  16. for (int i = 2; i * i <= MAXN; i++){
  17. if(spf[i] == i){
  18. for (int j = i*i; j <= MAXN; j += i){
  19. if(spf[j] == j){
  20. spf[j] = i;
  21. }
  22. }
  23. }
  24. }
  25.  
  26. }
  27.  
  28. unordered_map<int, int> calFactors(int n){
  29. unordered_map<int, int> mp;
  30.  
  31. while(n != 1){
  32. int d = spf[n];
  33. mp[d]++;
  34. n /= d;
  35. }
  36.  
  37. return mp;
  38. }
  39.  
  40.  
  41. signed main() {
  42. ios_base::sync_with_stdio(0);
  43. cin.tie(0); cout.tie(0);
  44.  
  45. // int t; cin >> t;
  46. // while (t--) {
  47. // solve();
  48. // }
  49. computeSpf();
  50. int n, m; cin >> n >> m;
  51. vector<int> input(n);
  52.  
  53. unordered_map<int, int> mp1;
  54. for (int i = 2; i <= m; i++){
  55. unordered_map<int, int> temp = calFactors(i);
  56.  
  57. for (auto itr: temp){
  58. mp1[itr.first] += itr.second;
  59. }
  60. }
  61.  
  62. for (int i = 0; i < n; i ++){
  63. unordered_map<int, int> mp2 = mp1;
  64. int g = 1;
  65. cin >> input[i];
  66.  
  67. unordered_map<int, int> factors = calFactors(input[i]);
  68.  
  69. for (auto itr : factors){
  70. mp2[itr.first] += itr.second;
  71. }
  72.  
  73. for (auto j : mp2){
  74. g = ((g % MOD) * ((j.second % MOD + 1 % MOD) % MOD)) % MOD;
  75. }
  76.  
  77. cout << g << " ";
  78. }
  79.  
  80. return 0;
  81. }
Success #stdin #stdout 0.02s 11104KB
stdin
3 3
1 2 3
stdout
4 6 6