Different answers in submit and custom test on 20 and 41


#1

void sieveOfEratosthenes(int N, int s[])
{
vector prime(N+1, false);
for (int i=2; i<=N; i+=2)
s[i] = 2;

for (int i=3; i<=N; i+=2) 
{ 
    if (prime[i] == false) 
    { 
        s[i] = i; 
        for (int j=i; j*i<=N; j+=2) 
        { 
            if (prime[i*j] == false) 
            { 
                prime[i*j] = true; 
                s[i*j] = i; 
            } 
        } 
    } 
} 

}
int Solution::cpFact(int N, int B) {
vector <pair<int, int>>pa;
int s[N+1];
sieveOfEratosthenes(N, s);
int curr = s[N]; // Current prime factor of N
int cnt = 1;
while (N > 1)
{
N /= s[N];
if (curr == s[N])
{
cnt++;
continue;
}
// cout<<curr<<" “<<cnt<<endl;
pa.push_back(make_pair(curr,cnt));
curr = s[N];
cnt = 1;
}
int ans=1;
for (int i=0; i<pa.size(); i++)
{
// cout<<pa[i].first<<” "<<pa[i].second<<endl;
if(B%pa[i].first!=0)
ans*=pow(pa[i].first,pa[i].second);
}
return ans;
}
On inputs 20,41
Custom test gives result 20, submit gives 4
why is this happening