Codeforces899C Dividing the numbers(数论)

本文提供CodeForces平台899/C题目的一种解决方案,介绍了一个C++程序,该程序能够根据输入的整数n计算出特定序列的绝对差值,并输出相应的序列。当序列总和为奇数时,绝对差为1;为偶数时,绝对差为0。

http://codeforces.com/problemset/problem/899/C

tot为奇数时,绝对差为1;tot为偶数时,绝对差为0。

难点在于如何输出。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cstdlib>
 6 #include<cmath>
 7 #include<vector>
 8 #include<stack>
 9 #include<queue>
10 #define lson l, m, rt<<1
11 #define rson m+1, r, rt<<1|1
12 #define IO ios::sync_with_stdio(false);cin.tie(0);
13 #define INF 0x3f3f3f3f
14 #define MAXN 500010
15 const int MOD=1e9+7;
16 typedef long long ll;
17 using namespace std;
18 ll n;
19 int main()
20 {
21     while(cin >> n){
22         ll tot = (1+n)*n/2;
23         if(tot&1){
24             cout << "1" << endl;
25             cout << n/2 << " ";
26         }
27         else{
28             cout << "0" << endl;
29             cout << n/2 << " ";
30         } 
31         for(int i = n, j = 0; i > 1; i -= 2, j = !j){
32             cout << i-j << " " ;
33         }
34         cout << endl;
35     }
36     return 0;
37 } 

 

转载于:https://www.cnblogs.com/Surprisezang/p/8727607.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值