Cod sursa(job #915936)

Utilizator Kira96Denis Mita Kira96 Data 15 martie 2013 16:25:16
Problema Sum Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include<fstream>
#include<string.h>
#define DIM 1500000
using namespace std;
ifstream f("sum.in");
ofstream g("sum.out");
int i,n,x,j,d;
long long nr;
char s[DIM];
int main ()
{
	f.get(s,DIM,EOF);
		x=0;
		while(s[i]<='9'&&s[i]>='0'){
			x=x*10+s[i]-'0'; ++i; }
		++i;
	for(;s[i];++i)
	{
		x=0;
		while(s[i]<='9'&&s[i]>='0'){
			x=x*10+s[i]-'0'; ++i; }
	d=x;
	nr=1;
	if(x%2==0)
	{
		x/=2;
		while(x%2==0)
		{
			x/=2;
			nr*=2;
		}
	}
	for(j=3;j*j<=x;++j)
	if(x%j==0)
	{
		nr*=(j-1);
		x/=j;
		while(x%j==0)
		{
			x/=j;
			nr*=j;
		}
	}
	if(x!=1)
		nr*=x-1;
	g<<2*nr*d<<"\n";
	}
	return 0;
}