Jump to content

[PROBLEMSET] Calculating Function


CouldnoT
 Share

Recommended Posts

Calculating Function

For a positive integer n let's define a function f:

f(n) =  - 1 + 2 - 3 + .. + ( - 1)^n*n

 

Your task is to calculate f(n) for a given integer n.

 

Input
 

The single line contains the positive integer n (1 ≤ n ≤ 1015).

 
Output
 

Print f(n) in a single line.

 

Examples :
 
input : 4
output : 2
 
Note:

f(4) =  - 1 + 2 - 3 + 4 = 2

 

I let you try it before having a look at my essay.

 

you are free to post your essays to discuss it in any language!

 

My essay :

 

 


program A486;
uses wincrt, sysutils;

var
	n: Int64;

function f(n : Int64): Int64;
var
	Result : Int64;
begin
	Result:=0; 
	if n mod 2 = 0 then
		Result:= n div 2
	else 
		Result:= (n div 2) - n;

	f:= Result;	
end;

begin
	readln(n);
	writeln(f(n));
	//readkey()
end.

 

 

codeforces.com

 

Edited by CouldnoT
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.