Last active
July 21, 2016 10:27
-
-
Save antonio-abrantes/cedc1f9933b9b4ef87365b69c2b96eb7 to your computer and use it in GitHub Desktop.
Soma Divisores com Raiz quadrada
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <math.h> | |
int main() | |
{ | |
int n, i, temp, quad; | |
while(scanf("%d",&n) != EOF){ | |
if(n == 0) | |
break; | |
int soma = 0; | |
quad = (int)sqrt(n); | |
//Realizar o calculo até a raiz quadrada do numero, reduzindo o tempo de execução... | |
for(i = 1;i <= quad; i++){ //Calcular a soma dos divisores sem incluir o numero de entrada... | |
if(n % i == 0){ | |
temp = n / i ; | |
if(temp == quad){ | |
soma = soma + n/i; | |
break; | |
} | |
soma = soma + temp + i; | |
} | |
} | |
printf("A soma e: %d \n",(soma - n)); // soma - n => para não incluir o numero de entrada a soma | |
//system("PAUSE"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment