cf1102A,水题

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值