Print sum of prime divisor
#include <bits/stdc++.h>
using namespace std;
bool isprime (int n)
{
if(n<=1)return false;
if(n<=3)return true;
if(n%2==0 || n%3==0)
return false;
for(int i=5; i*i<=n; i+=6)
{
if(n%i==0 || n%(i+2)==0)
return false;
}
return true;
}
int sumofdivisor(int n)
{
int sum=0;
for(int i=2; i<=n; i++)
{
if(n%i==0)
{
if(isprime(i))
{
sum+=i;
}
}
}
return sum;
}
int main ()
{
int t;
cin >> t;
while(t--)
{
int x;
cin >> x;
cout << sumofdivisor(x) << endl;
}
return 0;
}
Comments
Post a Comment