程式碼如下
#include <stdio.h>
#include <math.h>
int solution(int in,float d, int c = 2, int r = 0)
{
if (c > sqrt(d) || in == 1)
{
if (r==0) return d;
return in == 1 ? r : r + in;
}
if (in % c == 0)
{
r += c;
in /= c;
}
else
{
c++;
}
return solution(in,d, c, r);
}
int main()
{
int a = 0;
while (scanf_s("%d",&a)!=EOF)
{
printf("%d\n", solution(a,a));
}
return 0;
}
餵給系統後得到以下結果
您的答案為: 1000000000 正確答案為: 1000000007