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;
}