fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27. vector<int> spf;
  28. vector<int> primes;
  29.  
  30. void seive(){
  31. spf.assign(N+1, 0);
  32. for(int i=2; i<=N; i++) spf[i] = i;
  33.  
  34. for(int i=2; i*i<=N; i++){
  35. if(spf[i] != i) continue;
  36. for(int j=i*i; j<=N; j+=i){
  37. spf[j] = min(spf[j], i);
  38. }
  39. }
  40. for(int i=2; i<=100; i++){
  41. if(spf[i] == i) primes.push_back(i);
  42. }
  43. }
  44.  
  45.  
  46. vector<int> a;
  47.  
  48. //* Using spf to find factors of m!
  49.  
  50. vector<int> consistency1(int n, int m){
  51.  
  52. unordered_map<int,int> mp;
  53. for(int i=2; i<=m; i++){
  54. int q = i;
  55. while(q>1){
  56. mp[spf[q]]++;
  57. q /= spf[q];
  58. }
  59. }
  60.  
  61. vector<int> ans;
  62. for(auto& it : a){
  63.  
  64. int x = it;
  65. while(x>1){
  66. mp[spf[x]]++;
  67. x /= spf[x];
  68. }
  69.  
  70. int d = 1;
  71. for(auto& pe : mp){
  72. int e = pe.second;
  73. d = (d * (e+1))%M;
  74. }
  75. ans.push_back(d);
  76.  
  77. x = it;
  78. while(x>1){
  79. mp[spf[x]]--;
  80. x /= spf[x];
  81. }
  82. }
  83.  
  84. return ans;
  85.  
  86. }
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. //* Using legendre's formula to find factors of m!
  94.  
  95. vector<int> consistency2(int n, int m){
  96.  
  97. unordered_map<int,int> mp;
  98. for(auto& p : primes){
  99. int q = p;
  100. while(m/q>0){
  101. mp[p] += m/q;
  102. q *= p;
  103. }
  104. }
  105.  
  106. vector<int> ans;
  107. for(auto& it : a){
  108.  
  109. int x = it;
  110. while(x>1){
  111. mp[spf[x]]++;
  112. x /= spf[x];
  113. }
  114.  
  115. int d = 1;
  116. for(auto& pe : mp){
  117. int e = pe.second;
  118. d = (d * (e+1))%M;
  119. }
  120. ans.push_back(d);
  121.  
  122. x = it;
  123. while(x>1){
  124. mp[spf[x]]--;
  125. x /= spf[x];
  126. }
  127. }
  128.  
  129. return ans;
  130.  
  131. }
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148. vector<int> practice(int n, int m){
  149.  
  150.  
  151. }
  152.  
  153.  
  154.  
  155.  
  156.  
  157. void solve() {
  158. static int _ = (seive(), 0);
  159.  
  160. int n, m;
  161. cin>> n >> m;
  162.  
  163. a.resize(n);
  164. for(int i=0; i<n; i++) cin >> a[i];
  165.  
  166. auto ans = consistency1(n, m);
  167.  
  168. for(auto& it : ans) cout << it << " "; cout << endl;
  169.  
  170.  
  171. }
  172.  
  173.  
  174.  
  175.  
  176.  
  177. int32_t main() {
  178. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  179.  
  180. int t = 1;
  181. // cin >> t;
  182. while (t--) {
  183. solve();
  184. }
  185.  
  186. return 0;
  187. }
Success #stdin #stdout 0.01s 5480KB
stdin
3 3
1 2 3
stdout
4 6 6