题解 AT5632 【Sum of Two Integers】
rui_er
2020-02-13 09:51:26
题意:输入一个整数,求有多少个由两个**不同的正整数**组成的无序二元组(交换数字顺序视为同一种)加起来等于这个整数。
通过数学推理(以下的除号均表示整除运算):
如果输入的整数(设为 $n$)是奇数,则输出 $(n-1)\div 2$;否则输出 $n\div 2-1$,但根据整除运算也可写成 $(n-1)\div 2$。
Python:
```py
print((int(input())-1)//2)
```
C++:
```cpp
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
cout<<(n-1)/2<<endl;
return 0;
}
```
C:
```c
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
printf("%d\n", (n-1)/2);
return 0;
}
```
伪代码:
```
input n
n ← floor((n-1)/2)
print n
```