i have written the GP formula of sum of factors of a number x . but not able to process further .
Some hints please
@JARVIS17 Its kind of brute force approach (using Sieve ) calculate sum of factors of, till 10000 and check for what number sum if equal to s, (time complexity will be nlogn ) just now ✓
#include <bits/stdc++.h>
using namespace std;
int a[100000000];
int b[100000000]={0};
void sumofFactors(int n)
{
int m=n;
int res = 1;
for (int i = 2; i <= sqrt(n); i++)
{
int curr_sum = 1;
int curr_term = 1;
while (n % i == 0) {
n = n / i;
curr_term *= i;
curr_sum += curr_term;
}
res *= curr_sum;
}
if (n >= 2)
res *= (1 + n);
b[res]=res;
a[res]= m;
}
int main() {
b[1]=1;a[1]=1;
for(int i=2;i<=10000;i++){
sumofFactors(i);
// b[sumfact+i]=sumfact+i;
// a[sumfact+i]=i;
}
int x;cin>>x;
while(x!=0){
if(b[x]!=0){
cout<<a[x]<<endl;
}
else{
cout<<"-1"<<endl;
}
cin>>x;
}
} just now ✓
you can take reference from this code just now ✓
Feel free to ask any doubt in it
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.