题目:
A. Candies and Two Sisters time limit per test : 1 second memory limit
per test : 256 megabytes input : standard input output : standard
output There are two sisters Alice and Betty. You have n candies. You
want to distribute these n candies between two sisters in such a way
that: Alice will get a (a>0) candies; Betty will get b (b>0) candies;
each sister will get some integer number of candies; Alice will get a
greater amount of candies than Betty (i.e. a>b); all the candies will
be given to one of two sisters (i.e. a+b=n). Your task is to calculate
the number of ways to distribute exactly n candies between sisters in
a way described above. Candies are indistinguishable. Formally, find
the number of ways to represent n as the sum of n=a+b, where a and b
are positive integers and a>b. You have to answer t independent test
cases. Input The first line of the input contains one integer t
(1≤t≤104) — the number of test cases. Then t test cases follow. The
only line of a test case contains one integer n (1≤n≤2⋅109) — the
number of candies you have. Output For each test case, print the
answer — the number of ways to distribute exactly n candies between
two sisters in a way described in the problem statement. If there is
no way to satisfy all the conditions, print 0. Example: input: 6 7 1 2
3 2000000000 763243547 Out put: 3 0 0 1 999999999 381621773 Note For
the test case of the example, the 3 possible ways to distribute
candies are: a=6, b=1; a=5, b=2; a=4, b=3.
译文:
A.糖果和两个姐妹
每次测试的时限:1秒
每次测试的内存限制:256 MB
输入:标准输入
输出:标准输出
有两个姐妹爱丽丝和贝蒂。你有n个糖果。您要以以下方式在两个姐妹之间分配这些n个糖果:
爱丽丝会得到(a> 0)个糖果;
贝蒂将获得b(b> 0)个糖果;
每个姐姐都会得到一些整数的糖果;
爱丽丝会得到比贝蒂更多的糖果(即a> b);
所有的糖果都将送给两个姐妹之一(即a + b = n)。
您的任务是计算以上述方式在姐妹之间准确分配n个糖果的方式数量。糖果是无法区分的。
形式上,找到将n表示为n = a + b的总和的方式数量,其中a和b是正整数,而a> b。
您必须回答t个独立的测试用例。
输入值
输入的第一行包含一个整数t(1≤t≤104)-测试用例的数量。然后是t个测试用例。
测试用例的唯一一行包含一个整数n(1≤n≤2⋅109)-您拥有的糖果数。
输出量
对于每个测试用例,请打印答案-以问题陈述中所述的方式在两个姐妹之间准确分配n个糖果的方法的数量。如果无法满足所有条件,请打印0。
例:
输入:
6
7
1个
2
3
2000000000
763243547
输出:
3
0
0
1个
999999999
381621773
注意
对于该示例的测试案例,分配糖果的3种可能方法是:
a = 6,b = 1;
a = 5,b = 2;
a = 4,b = 3。
这道题简要说一下就是分糖果给两个人,一个人的糖果一定要比另一个人多,直接开始枚举!
#include <bits/stdc++.h>
using namespace std;
int t,n;
int main()
{
cin >> t;
for(int i = 0; i < t; i++)
{
cin >> n;
if(n % 2 == 0)
{
cout << n / 2 - 1 << endl;
}
else
{
cout << n / 2 << endl;
}
}
return 0;
}
点个赞再离开吧!