Cod sursa(job #999696)

Utilizator SkillZoneOvy The Best SkillZone Data 21 septembrie 2013 11:46:16
Problema Sum Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.48 kb
#include<fstream>
using namespace std;
bool v[200001];
int cmmdc(int a, int b){
	if(a%b==0)
		return b;
	else return cmmdc(b,a%b);
}
int main(){
	int n,x;
	long long s;
	ifstream f("sum.in");
	ofstream g("sum.out");
	f>>n;
	for(int i=0;i<n;i++){
		f>>x;
		for(int l=2;l<=x*2;l++)
			if(cmmdc(l,x)!=1)
				for(int j=l;j<=x*2;j+=l)
					v[j]=1;
		s=1;
		for(int j=2;j<x*2;j++)
			if(!v[j])
				s+=j;
		g<<s<<'\n';
		for(int i=2;i<x*2;i++)
			v[i]=0;
	}
	return 0;
}