Cod sursa(job #1982983)
| Utilizator | Data | 20 mai 2017 20:51:37 | |
|---|---|---|---|
| Problema | Sum | Scor | 35 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.6 kb |
#include <fstream>
using namespace std;
int gcd(int a, int b)
{
if (b != 0) {
return gcd(b, a % b);
}
return a;
}
long long calc(int x) {
long long s = 0;
for (int i = 1; i <= 2 * x; i++) {
if (gcd(i, x) == 1) {
s += i;
}
}
return s;
}
int main() {
ifstream cin ( "sum.in");
ofstream cout("sum.out");
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
cout << calc(x) << '\n';
}
cin. close();
cout.close();
return 0;
}
