I could not understand promlem.
How for sample input 5 sample output will be 1.
Please describe me.
This problem was set by shahriarmonzoor.
Moderator: Board moderators
program kpC;
label finish;
var
res: int64;
procedure init;
begin
end;
procedure solve;
var
k: integer;
rese: extended;
n: int64;
begin
k:= 0;
while true do begin
readln(n);
if n=0 then exit;
inc(k);
if odd(n) then begin
res:= n+3;
res:= res*res;
rese:= res/48;
if abs(rese-trunc(rese)-0.5)<0.0000000001 then
if odd(trunc(rese)) then res:= trunc(rese)+1
else res:= trunc(rese)
else res:= round(rese);
end else begin
res:= n;
res:= res*res;
rese:= res/48;
if abs(rese-trunc(rese)-0.5)<0.0000000001 then
if odd(trunc(rese)) then res:= trunc(rese)+1
else res:= trunc(rese)
else res:= round(rese);
end;
writeln('Case ',k,': ',res);
end;
end;
procedure print;
begin
end;
begin
{$IFNDEF ONLINE_JUDGE}
assign(input,'input.txt'); reset(input);
assign(output,'output.txt'); rewrite(output);
{$ENDIF}
init;
solve;
print;
finish:
{$IFNDEF ONLINE_JUDGE}
close(input); close(output);
{$ENDIF}
end.

res:= n+3;
res:= res*res;
res:= (res+24) div 48;

sohel wrote:It becomes summation of two arithmatic series
int getPart(int v, int mside) {
return mside-(v+1)/2+1;
}
little joey wrote:kp:
The function round() can handle only numbers within the range of integers (-2^31<= number < 2^31). Outside this range the function will produce a runtime error, which the Judge reports as WA.
Better not rely on floating point numbers and round(), but do the rounding yourself:
- Code: Select all
res:= n+3;
res:= res*res;
res:= (res+24) div 48;

Chok wrote:Hi,
I'm also using those close form, but since contest time all of my submission leads WA. I used long long for taking input and then after dividing by a constant value then i use (floor(tmp+.5)). Is it ok ? In others problem i did this things for rounding upto nearest integer. But i dont know why i gets WA for this problem.
long long x=7;
double y=x/2;

little joey wrote:1. The judge uses fpc (Free Pascal Compiler) and not Delphi. In the version of fpc the judge uses all functions that return integers, return 32 bits integers (I think fpc also has a 64 bits version, but the judge doesn't use that).
little joey wrote:2. ... It's a real pain in the neck and the main reason why I switched from Pascal to C.
Users browsing this forum: No registered users and 1 guest