Pagini recente » Cod sursa (job #419853) | Cod sursa (job #492082) | Profil MihneaGhira | Cod sursa (job #1553544) | Cod sursa (job #1603948)
type vector=array[1..100000] of boolean;
var ciur:vector;
n,x,i,suma,j:longint;
function cmmdc(a,b:longint):integer;
begin
if a=b then cmmdc:=a
else if a>b then cmmdc:=cmmdc(a-b,b)
else cmmdc:=cmmdc(a,b-a);
end;
procedure Ninicutostene(x:longint;var ciur:vector);
var i,j:longint;
begin
for i:=1 to x do ciur[i]:=false;
for i:=1 to x div 2 do
begin
if cmmdc(i,x div 2)=1 then
begin
j:=i;
while (j<=x) do
begin
ciur[j]:=true;
j:=j+x div 2;
end;
end;
end;
// for i:=1 to x do if ciur[i] then write(i,' ');
// readln;
// readln;
end;
begin
assign(input,'sum.in'); reset(input);
assign(output,'sum.out');rewrite(output);
// readln(input,n);
// max:=0;
// for i:=1 to n do
// begin
// readln(input,x);
// if x>max then max:=x;
// end;
// Ninicutostene(max*2,ciur);
// for i:=1 to max*2 do if ciur[i] then write(i,' ');
// readln;
// reset(input);
suma:=0;
readln(input,n);
for i:=1 to n do
begin
readln(input,x);
ninicutostene(x*2,ciur);
for j:=1 to x*2 do if (ciur[j]) then
begin
if cmmdc(x,j)=1 then suma:=suma+j;
end;
writeln(suma);
suma:=0;
end;
close(input);
close(output);
end.