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 ...
随机推荐
- git-format-patch
使用方法: git diff ${old-commit} ${new-commit} > commit-operation.patch OR git format- b1af44f > c ...
- qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory
执行 qmake -v 出现错误:qmake: could not exec ‘/usr/lib/x86_64-linux-gnu/qt4/bin/qmake’: No such file or di ...
- 使用yield生成器,用Python实现用户对用户输入信息的监听和过滤
# -*- coding:utf-8 -*-'''''''''生成器是一次生成一个值的特殊类型函数.可以将其视为可恢复函数.调用该函数将返回一个可用于生成连续 x 值的生成[Generator],简单 ...
- nmcli命令使用以及网卡绑定bond
一.nmcli命令 1.什么是nmcli 以前我配置网卡的时候都要打vim /etc/sysconfig/network-scripts/ifcfg-eth0这么一长串命令,有很多配置名字还记不住就需 ...
- Exp3 免杀原理与实践 20164320 王浩
一.实验内容 1.1 正确使用msf编码器(0.5分),msfvenom生成如jar之类的其他文件(0.5分),veil-evasion(0.5分),加壳工具(0.5分),使用shellcode编程( ...
- Windows10 正式企业版激活
一.镜像 https://www.landiannews.com/archives/51102.html 二.ISO镜像文件比对SHA1值,判定文件是否被篡改 https://msdn.itellyo ...
- 如何彻底禁止win10易升更新(转)
原文:https://blog.csdn.net/qq_33075489/article/details/79755896 add by zhj: 第二步是我自己加的 Win10版本:家庭中文版64位 ...
- 学习h264 的语法规则,如何才能看懂H264 的官方文档
1. 今天想查h264 的帧率,查找资料如下: 首先要解析sps,得到两个关键的数值: num_units_in_tick, time_scale fps=time_scale/num_units_i ...
- redis 3.2 新数据结构:quicklist、String的embstr与raw编码方式分界点
Redis3.2.0引入了新的quicklist的数据结构做了list的底层存储方案.废弃了原来的两个配置参数, list-max-ziplist-entries list-max-ziplist-v ...
- 框架的一些bug问题记录
关于java后台生成的mis表,在添加的add页面和edit页面中无法显示,去控制台里面查看.会有些错误的信息,是由于,你的那些html的标签不正常.导致无法显示. 里面有一个高级搜索,可以对这个选择 ...