CodeForces - 1102A
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的更多相关文章
- 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 ...
- CodeForces - 1102A(思维题)
https://vjudge.net/problem/2135388/origin Describe You are given an integer sequence 1,2,-,n. You ha ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- 循环结构while
Note:高能:语句结构都是由关键字开头,用冒号结束! 一:语句结构 while 判断条件: 语句 二:基本规则 (1)使用缩进来划分语句块,相同缩进数的语句在一 ...
- 基于贝叶斯算法实现简单的分类(java)
参考文章:https://blog.csdn.net/qq_32690999/article/details/78737393 项目代码目录结构 模拟训练的数据集 核心代码 Bayes.java pa ...
- MacBook Air 装win10系统 by DODUI
为了给齐哥更完美的体验Windows10系统,DODUI亲手操刀MacBook双系统安装Win10,双系统安装教程如下: 终于遇到各种奇葩问题,给小伙伴分享一下. 双系统安装Win10准备工具: 1. ...
- 提高你的python:解释 yield 和 Generators(生成器)
转自:http://www.oschina.net/translate/improve-your-python-yield-and-generators-explained 原文:http://www ...
- 壁虎书7 Ensemble Learning and Random Forests
if you aggregate the predictions of a group of predictors,you will often get better predictions than ...
- 内置对象之request对象
内置对象就是(容器)已经创建好的对象,可以被直接使用.当用户发送一个请求给容器,它就会自动创建一个对象来处理客户端发送来的消息,如request这个对象,可以获取到用户(客户端)发送来的信息.它的常见 ...
- jQuery地图插件jVectorMap的简单使用
1.官网下载jVectorMap插件压缩文件 官网地址:http://www.jvectormap.com/ 2.解压文件包括jVectorMap库及基础样式表,编写Html文件,引入jQuery框架 ...
- 二、jspxcms使用-用户和模型
原本想二次开发,后来放弃了,里面东西很多. 1.用户 菜单位置:用户权限 注意:用户中 id为0和1的用户为默认用户,不要删,0是默认管理员用户,1是匿名账户. 会 ...
- 【PY】Python3.7+Anaconda3 + PyQt5 + Eric6
Anaconda下载地址:https://www.continuum.io/downloads pip install pyenchant pip install QScintilla pip ins ...
- MongoDB系列----uupdate和数组
db.collection.update( criteria, objNew, upsert, multi ) criteria : update的查询条件,类似sql update查询内where后 ...