#include
using namespace std;
int main(){
int t;
cin>>t;
while(t–){
long n;
cin>>n;
long j =0;
long a[n];
long sum=0;
for(long i = 1;i<=n;i++){
if(n%i==0)
{
if(i%2!=0){
sum+=i;
}
}
}
cout<<sum+1;
cout<<"\n";
}
return 0;
}
#include
using namespace std;
int main(){
int t;
cin>>t;
while(t–){
long n;
cin>>n;
long j =0;
long a[n];
long sum=0;
for(long i = 1;i<=n;i++){
if(n%i==0)
{
if(i%2!=0){
sum+=i;
}
}
}
cout<<sum+1;
cout<<"\n";
}
return 0;
}
hello @Aditikumari
the approach u are applying is not efficient ,and it will give tle
so do a precomputation and store value of g(i) for i from 1 to 10^6 in some array .
then answer for each test case in O(1) using g array.
sir please provide me with code. i amnot able to understand
ignore the relation i have written above.
here the technique is very similar to sieve.
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.