codeforces 1102A

codeforces 1102A

题目链接:codeforces
problem:
Integer Sequence Dividing
problem description:

       you are given an integer sequence 1,2,…,𝑛. You have to divide it into two sets 𝐴 and 𝐵 in such a way that each element belongs to exactly one set and |𝑠𝑢𝑚(𝐴)−𝑠𝑢𝑚(𝐵)| is minimum possible.

       The value |𝑥| is the absolute value of 𝑥 and 𝑠𝑢𝑚(𝑆) is the sum of elements of the set 𝑆.


Input:

The first line of the input contains one integer 𝑛 (1≤𝑛≤2⋅109).


Output:

Print one integer — the minimum possible value of |𝑠𝑢𝑚(𝐴)−𝑠𝑢𝑚(𝐵)| if you divide the initial sequence 1,2,…,𝑛 into two sets 𝐴 and 𝐵.


Examples:

input:
3
output:
0
input:
5
output:
1
input:
6
output:
1


Note:

Some (not all) possible answers to examples:

In the first example you can divide the initial sequence into sets 𝐴={1,2} and 𝐵={3} so the answer is 0.

In the second example you can divide the initial sequence into sets 𝐴={1,3,4} and 𝐵={2,5} so the answer is 1.

In the third example you can divide the initial sequence into sets 𝐴={1,4,5} and 𝐵={2,3,6} so the answer is 1.


比较水的思维题,一开始用暴力,错了两次超时,后面发现是简单的思维题,直接贴代码,一看就懂。

#include<stdio.h>
int main()
{
    int i,sum;
    while(~scanf("%d",&i))
    {
        sum=(i*i+i)/2;//等差数列求和
        if(sum%2==0)
            printf("0\n");
        else
            printf("1\n");
    }
    return 0;
}
posted @ 2019-01-21 18:14  丶斗北  阅读(192)  评论(0)    收藏  举报