Hello!
For some reason, I've tried all the test cases provided, yet it (the judge) always reports WA!
Can someone figure out what's wrong?
#include <iostream>
#include <stdio.h>
using namespace std;
int p[168];
bool prime[1000];
int i,j,k;
int t,n,inp;
inline long power(int a,int b)
{
long res = 1;
while (b--)
res *= a;
return res;
}
main(){
for (i = 0; i < 1000; i++)
prime[i] = true;
prime[0] = prime[1] = false;
prime[2] = true;
k = 0;
for (i = 2; i < 1000; i++)
if (prime[i])
{
p[k++] = i;
for (j = 2*i; j < 1000; j += i)
prime[j] = false;
}
cin >> t;
while (t--)
{
scanf("%d",&inp);
n = inp;
long sum = 1;
if (n==1)
{
sum = 0;
goto done;
}
for (i = 0; i < k; i++)
{
if (n<p[i])
break;
int d = 0;
while (n%p[i]==0&&n>=p[i])
{
n /= p[i];
d++;
}
sum *= ((power(p[i],d+1)-1)/(p[i]-1));
}
sum -= inp;
done:printf("%ld",sum);
if (t)
printf("%\n");
}
return 0;
}