You are given an integer sequence 1,2,…,n1,2,…,n. You have to divide it into two sets AA and BB in such a way that each element belongs to exactly one set and |sum(A)−sum(B)||sum(A)−sum(B)| is minimum possible.

The value |x||x| is the absolute value of xx and sum(S)sum(S) is the sum of elements of the set SS.

Input
The first line of the input contains one integer nn (1≤n≤2⋅1091≤n≤2⋅109).

Output
Print one integer — the minimum possible value of |sum(A)−sum(B)||sum(A)−sum(B)| if you divide the initial sequence 1,2,…,n1,2,…,n into two sets AA and BB.

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 A={1,2} and B={3} so the answer is 00.

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

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

解题思路:先求出前n项的和,如果前n项和为偶数,则总能找到两个子集的和相等;若为奇数,则总能找到两个子集和相差为1.

include<stdio.h>

int main()
{
long long n,ans;
while(~scanf("%lld",&n))
{
ans=(1+n)*n/2;
if(ans%2==1)
printf("1\n");
else if(ans%2==0)
printf("0\n");
}
}

CodeForces - 1102A的更多相关文章

  1. Integer Sequence Dividing CodeForces - 1102A (规律)

    You are given an integer sequence 1,2,…,n1,2,…,n. You have to divide it into two sets AAand BB in su ...

  2. CodeForces - 1102A(思维题)

    https://vjudge.net/problem/2135388/origin Describe You are given an integer sequence 1,2,-,n. You ha ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. Oracle视图 create View

    视图是一种虚表,使用CREATE VIEW语句来定义视图,该视图是基于一个或多个表或视图的逻辑表.一个视图本身不包含任何数据, 视图所基于的表称为基表. 视图就相当于一条select 语句,定义了一个 ...

  2. 2019.3.22 JMeter基础操作

    1.添加线程组:testplan—添加—线程(用户)Threads(Users) 线程属性值:线程数(虚拟用户数).Rump-up(准备时长:设置所有线程全部启动时间).循环次数(每个线程重复发送请求 ...

  3. ubuntu16.04安装mrpt

    源码地址 https://github.com/MRPT/mrpt 安装教程 https://github.com/MRPT/mrpt/blob/master/README.md#32-build-f ...

  4. ide phpStorm 配置PHP路径并本地执行PHP脚本

    1.打开设置(File - Settings) 2. 3. 4.到需要执行脚本的文件处,右击 - Run 5.如果本地还未安装PHP,可以下载Xampp,并将PHP目录新增至系统环境变量Path处,重 ...

  5. Android的SQlite的使用

    Android系统集成了一个轻量级的数据库:SQlite.SQlite不像Oracle.MySQl数据库那样需要安装.启动服务器进程,SQLite数据库只是一个文件 实例1:向数据库里插入数据 主界面 ...

  6. ReactJS antd 环境中项目上传图片后压缩(lrz的使用)

    lrz说明 ( github地址 :https://github.com/think2011/localResizeIMG ) 用于:在客户端压缩好要上传的图片可以节省带宽更快的发送给后端,特别适合在 ...

  7. 多个.txt文件合并到一个.txt文件中

    如果想要将多个.txt文件合并到一个.txt文件中,可以先将所有.txt文件放到一个文件夹中,然后使用.bat文件完成任务. 例如,在一个文件夹下有1.txt, 2.txt, 3.txt三个文件,想把 ...

  8. 常用Java技术社区

      Java生态圈知识链: 求职平台 阿里巴巴社招平台 杭州网易社招平台 微店社招平台 银联社招平台 百度社招平台 Java生态圈知识链: 个人优秀博客 腾讯_运维工程师_刘天斯 阿里_Android ...

  9. opencart3修改产品页模板没有效果的原因排查

    这几天在opencart 3模板时发生了一个很奇怪的事情,ytkah明明已经将product.twig模板修改了,但是前端产品页就是没有变化,后台刷新缓存了也不起左右.后面想着把模板重命名成produ ...

  10. selenium操作浏览器cookies

    package test; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; imp ...