can somebody please help me
I just want to know why im getting wa
Please
Thanks in advance!!
// priority_queue is generally max heap to make it min heap use priority_queue<int,vector<int>,greater<int>> pq;"
#include<cstdio>
#include<stdio.h>
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<cstring>
#include<math.h>
#include <iterator>
#define int long long int
#define double long double
#define pb push_back
#define mod 1000000007
using namespace std;
int gcd(int a,int b)
{
if(b==0)
return a;
gcd(b,a%b);
}
int prime[1000009];
vector<int> v;
void sieve()
{int i,j;
int b[1000009];
memset(prime,0,sizeof(prime));
memset(b,0,sizeof(b));
for(i=2;i<1000009;i++)
{
if(b[i]==0)
{
v.pb(i);
prime[i]=1;
for(j=2*i;j<1000009;j=j+i)
b[j]=1;
}
}
}
int bs(pair<int,int> p[],int n,int key,int i)
{
int low=i,high=n-1;
int ans=-1;
while(low<=high)
{
int mid=low+high;
mid=mid/2;
if(p[mid].first>key)
high=mid-1;
else {
low=mid+1;
ans=mid;
}
}
return ans;
}
int gcdExtended(int a, int b, int *x, int *y);
// Function to find modulo inverse of a
int modInverse(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
if (g != 1)
cout << "Inverse doesn't exist";
else
{
// m is added to handle negative x
int res = (x%m + m) % m;
return res;
}
}
// C function for extended Euclidean Algorithm
int gcdExtended(int a, int b, int *x, int *y)
{
// Base Case
if (a == 0)
{
*x = 0, *y = 1;
return b;
}
int x1, y1; // To store results of recursive call
int gcd = gcdExtended(b%a, a, &x1, &y1);
// Update x and y using results of recursive
// call
*x = y1 - (b/a) * x1;
*y = x1;
return gcd;
}
struct piyush {
int tm;
int fa;
int fb;
};
bool operator<(piyush a,piyush b)//sorting for sets
{
return a.tm>b.tm;
}
bool cmp(piyush a,piyush b)
{
return a.tm<b.tm;
}
signed main()
{
int n,i,j,k,t,m;
cin>>t;
sieve();
while(t--)
{
int x;
cin>>k>>x;
if(prime[x])
{
if(k==1)
{
cout<<x<<endl;
}
else if(k==2)
{
cout<<x+1<<endl;
}
else
{
cout<<(k-2)+x+1<<endl;
}
continue;
}
int minans=10000000000;
int k1=k;
for(i=1;i<=sqrt(x);i++)
{
if(x%i==0)
{
j=x/i;
k=gcd(j,i);
/// cout<<j<<" "<<i<<endl;
/// cout<<k<<endl;
if(k==1)
minans=min(minans,j+i);
}
}if(k1==2)
cout<<minans+k1-2<<endl;
else
{
int jk=x;
vector<int> vv;
for(auto pm:v)
{
if(pm<=x)
{
k=0;
int val=1;
while(x%pm==0)
{
x=x/pm;
k++;
val=val*pm;
}
if(val>1)
{
vv.pb(val);
}
}
else
{
break;
}
}if(x>1)
vv.pb(x);
if(k1>=vv.size())
{
int sum=0;
k=vv.size();
for(auto pm:vv)
sum+=pm;
cout<<sum+k1-k<<endl;
continue;
}
else
{
////sort(vv.begin(),vv.end());
k=vv.size();
multiset<int> s;
for(auto xx:vv)
s.insert(xx);
while(s.size()!=k1)
{
int val=*s.begin();
s.erase(s.begin());
int val2=*s.begin();
s.erase(s.begin());
s.insert(val*val2);
}
int need=0;
for(auto xx:s)
need+=xx;
cout<<need<<endl;
}
}
}
}