Codeforces Round #277 (Div. 2)-A. Calculating Function (规律)_html/css_WEB-ITnose
程序员文章站
2022-05-21 12:10:29
...
Calculating Function
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
For a positive integer n let's define a function f:
f(n)?=??-?1?+?2?-?3?+?..?+?(?-?1)nn
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.
Sample test(s)
input
output
input
output
-3
Note
f(4)?=??-?1?+?2?-?3?+?4?=?2
f(5)?=??-?1?+?2?-?3?+?4?-?5?=??-?3
解题思路:大水题一枚,直接找规律。n%2==0时,f = n/2; 否则,f = -(n+1)/2.
AC代码:
#include#include #include #include #include #include #include #include
推荐阅读
-
Codeforces Round #156 (Div. 2)-A. Greg's Workout_html/css_WEB-ITnose
-
Codeforces Round #107 (Div. 2)-A. Soft Drinking_html/css_WEB-ITnose
-
Codeforces Round #191 (Div. 2)-A. Flipping Game_html/css_WEB-ITnose
-
Codeforces Beta Round #75 (Div. 2)-A. Chips_html/css_WEB-ITnose
-
Codeforces Round #144 (Div. 2)-A. Perfect Permutation_html/css_WEB-ITnose
-
Codeforces Round #135 (Div. 2)-A. k-String_html/css_WEB-ITnose
-
Codeforces Round #256 (Div. 2) A. Rewards_html/css_WEB-ITnose
-
Codeforces Round #175 (Div. 2)-A. Slightly Decreasing Permutations_html/css_WEB-ITnose
-
Codeforces Round #112 (Div. 2)-A. Supercentral Point_html/css_WEB-ITnose
-
Codeforces Round #190 (Div. 2)-A. Ciel and Dancing_html/css_WEB-ITnose