I tried doing %mod wherever I’m multiplying or adding something. Can’t figure out the mistake. Please help.
Getting wrong answer for two out of 3 testcases. Working correctly for the given testcases
#include<bits/stdc++.h> #define int long long #define mod 1000000007 using namespace std; map <int,int> mp; int sieve[1000002] = {0}; vector primes; void primeFactorize(int n) { int num; for(auto i= primes.begin(); i != primes.end(); i++){ num = i; if(num > n){ break; } if(n%num == 0){ while(n%num == 0){ n = n/num; mp[num]++; mp[num] = mp[num]%mod; } } } return; } int32_t main(){ sieve[2] = 1; sieve[3] = 1; int sievesize = 1000000; for(int i=3; i<=sievesize; i+=2){ sieve[i] = 1; } primes.push_back(2); for(int i=3; ii<=sievesize; i+=2) { if(sieve[i]==1){ primes.push_back(i); for(int j=ii; j<=sievesize; j+=i){ sieve[j] = 0; } } } int t; cin >> t; while(t–) { int n; cin >> n; int arr[n]; for(int i=0; i<n; i++) { cin >> arr[i]; primeFactorize(arr[i]); } int pow; int ans = 1; for(auto it:mp){ pow = it.second + 1; ans = anspow; ans = ans%mod; } cout << ans << endl; mp.clear(); } return 0; }
You needed to calculate primes up until sievesize. I corrected your code here https://ide.codingblocks.com/s/426037
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.