Computer Science, asked by TbiaSamishta, 11 months ago

Se citește un număr natural n. Să se determine suma divizorilor impari ai săi.

Answers

Answered by aqibkincsem
0

The best Solution is to form an iteration of the numbers from 1 to along with keeping a check that if the number divides n and simultaneously prints it.

For instance, if the input is n = 100, then the output will be 1 2 4 5 10 20 25 50 100

Answered by andreiulRO
0

#include <iostream>

using namespace std;

int n,d,s;

int main()

{

   cin>>n;

   for(d=1;d*d<n;d++)

   {

       if(n%d==0)

        {

            if(d%2==1) s=s+d;

            if((n/d)%2==1) s=s+n/d;

        }

   }

   if((d*d==n)&&(d%2==1)) s=s+d;

   cout<<s;

   return 0;

}

Similar questions