Cod sursa(job #974881)

Utilizator bgdiBogdan Angheluta bgdi Data 18 iulie 2013 16:52:57
Problema Sum Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
// Sum.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;

ifstream fin ("sum.in");
ofstream fout ("sum.out");

int n, x, i, j, div_max=0, a, b, rest;
long int sum;

int main()
{
	fin>>n;
	for (i=1; i<=n; i++) {
		sum=0;
		fin>>x;
		for (j=1; j<2*x; j++) {
			if (j%x!=0) {
				rest=1;
				a=j; b=x;
				while (rest!=0) {
				rest=a%b;
				a=b;
				b=rest;
				}
				if (a==1)
					sum=sum+j;
			}
		}
		fout<<sum<<"\n";
	}
	return 0;
}