What's wrong in my code logic?

typedef long long ll;
#define FR(i,a,b) for(int i=(a);i<(b);i++)
const int MAX=1e6+5;
int n=0,i=0,j=0;
int s[MAX];
void fil()
{
FR(i,1,MAX)s[i]=1;
for(i=2;i<MAX;i++)
{
for(j=i;j<MAX;j+=i)
s[j]+=i;
}
}

void solve()
{
while (1)
{
cin>>n;
if(n==0)return;
FR(i,1,MAX)
if(s[i]==n)
{
cout<<i<<"\n";
n=-1;
break;
}
if(n!=-1)cout<<"-1\n";
}
}

signed main()
{
fil();
solve();
return 0;
}

hey @yaduvanshii092 your code isn’t readable here
You can share this code using ide.codingblocks.com

  • A special url will be generated, share that url with me

your logic is correct to calculate seive, but in main function what you are computing is taking time. Now do what , since you have Find all the primes till 10^5 using seive. Now find sum of factors of numbers using prime numbers and (Mathematical formula sum of factors) Now for every test case simply check if it exist in array or not.
like this

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.