跳到正文

题解

题解 AT5632 【Sum of Two Integers】

rui_er约 1 分钟
原文
文章信息与版本

文章信息

发布
2020年2月13日
收录
2025年12月12日
更新
2026年10月28日
篇幅
约 1 分钟

版本

  1. v1当前

题意:输入一个整数,求有多少个由两个不同的正整数组成的无序二元组(交换数字顺序视为同一种)加起来等于这个整数。

通过数学推理(以下的除号均表示整除运算):

如果输入的整数(设为 nn)是奇数,则输出 (n−1)÷2(n-1)\div 2;否则输出 n÷2−1n\div 2-1,但根据整除运算也可写成 (n−1)÷2(n-1)\div 2。

Python:

Python
print((int(input())-1)//2)

C++:

C++
#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
原文
存档评论1 条抓取于