Cod sursa(job #728245)
| Utilizator | Data | 28 martie 2012 16:31:06 | |
|---|---|---|---|
| Problema | Sum | Scor | 45 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.53 kb |
#include <fstream>
using namespace std;
int cmmdc(int a, int b)
{
int c=a%b;
while(c)
{
a=b;
b=c;
c=a%b;
}
return b;
}
//bool valid[200001];
int main()
{
int n, i, x, j, sum=1, k;
ifstream f("sum.in");
ofstream g("sum.out");
f>>n;
for(i=1; i<=n; i++)
{
f>>x;
/*for(j=2; j<2*x; j++)
{
valid[j]=false;
}*/
sum=1;
for(j=2; j<2*x; j++)
{
if(cmmdc(j, x)==1 /*&& !valid[j]*/)
sum+=j;
/*else for(k=j+j; k<2*x; k+=j)
{
valid[k]=true;
}*/
}
g<<sum<<"\n";
}
}