在幼儿园的时候,我们就学习过把一个数分成\(a\)与\(b\),我们只需要用计算机来模拟这个过程就可以了。

我们先从奇数开始看起,以\(5\)为例:

我们可以发现,\(5\)可以分成\(1\)和\(4\),\(2\)和\(3\),\(3\)和\(2\),以及\(4\)和\(1\),也就是说,一个奇数可以有\(n-1\)种方法进行分解,去重后也就是\((n-1)\div2\)种方法。

可以在举一个例子,如\(7\),它可以分成\(1\)和\(6\),\(2\)和\(5\),\(3\)和\(4\),\(4\)和\(3\),\(5\)和\(2\),\(6\)和\(1\),去重后就是\(1\)和\(6\),\(2\)和\(5\),\(3\)和\(4\),共\(3\)种,再用刚刚推出的公式,\((7-1) \div 2 = 3\),发现公式是正确的。

再看偶数,在这里以\(4\)为例。

我们可以发现,一共有\(3\)种方法可以将\(4\)分解,和奇数一样,也有\(n-1\)种方案,其中,\(2\)与\(2\)是重复的,去掉,\(3\)和\(1\)也是重复的,去掉。因此我们发现,\(4\)只有\(1\)和\(3\)一种分解方法,可以用\((n-1)\div2\)的方法判断。

最后我们发现,他们的公式都一样,所以可以直接套公式。

#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
cout<<(n-1)/2;
return 0;
}

题解 AT5632 【Sum of Two Integers】的更多相关文章

  1. LeetCode Sum of Two Integers

    原题链接在这里:https://leetcode.com/problems/sum-of-two-integers/ 题目: Calculate the sum of two integers a a ...

  2. [LeetCode] Sum of Two Integers 两数之和

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  3. Nim Game,Reverse String,Sum of Two Integers

    下面是今天写的几道题: 292. Nim Game You are playing the following Nim Game with your friend: There is a heap o ...

  4. LeetCode 371. Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  5. leetcode371. Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  6. 【LeetCode】Sum of Two Integers

    问题描述: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and - ...

  7. 每天一道LeetCode--371. Sum of Two Integers

    alculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Examp ...

  8. 371. Sum of Two Integers -- Avota

    问题描述: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and - ...

  9. Leetcode 371: Sum of Two Integers(使用位运算实现)

    题目是:Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. ...

  10. LeetCode 371. Sum of Two Integers (两数之和)

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

随机推荐

  1. 06-Spring03-事务管理

    今日知识 1. Spring事务管理 2. 转账案例 Spring事务管理 1. 事务特性(ACID) 1. 原子性:整体 [原子性是指事务包含的所有操作要么全部成功,要么全部失败] 2. 一致性:数 ...

  2. Memcache 安装配置使用

    Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.                                                     ...

  3. 管理 使用 FastDFS

    启动管理tracker: 1. 启动文件+配置文件+命令 /usr/bin/fdfs_trackerd <config_file> [start | stop | restart] 举例: ...

  4. ubuntu python及python IDLE 的安装

    ubuntu下Python的安装和使用 文章参考出处:https://www.cnblogs.com/luckyalan/p/6703590.html ubuntu14.04 安装Python2.7: ...

  5. 1058 - Parallelogram Counting 计算几何

    1058 - Parallelogram Counting There are n distinct points in the plane, given by their integer coord ...

  6. 手把手带你阅读Mybatis源码(三)缓存篇

    前言 大家好,这一篇文章是MyBatis系列的最后一篇文章,前面两篇文章:手把手带你阅读Mybatis源码(一)构造篇 和 手把手带你阅读Mybatis源码(二)执行篇,主要说明了MyBatis是如何 ...

  7. 修饰符 public、 private 和 protected和区别

    TypeScript 可以使用三种访问修饰符(Access Modifiers),分别是 public.private 和 protected. public 修饰的属性或方法是公有的,可以在任何地方 ...

  8. git系列之---码云gitee 添加SHH公钥

    公钥 很多服务器都是需要认证的,SHH 认证是其中的一种:在客户端生成公钥,把生成的公钥添加到服务器,你以后连接服务器的时候就不用每次都输入用户名和密码了:很多git服务器都是用ssh认证方式,你需要 ...

  9. 面试官:你用过mysql哪些存储引擎,请分别展开介绍一下

    这是高级开发者面试时经常被问的问题.实际我们在平时的开发中,经常会遇到的,在用SQLyog等工具创建表时,就有一个引擎项要你去选.如下图: Mysql的存储引擎有这么多种,实际我们在平时用的最多的莫过 ...

  10. UCF Local Contest 2015 J 最小割

    题意: 有