-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcandies_and_sisters.cpp
More file actions
78 lines (59 loc) · 1.56 KB
/
candies_and_sisters.cpp
File metadata and controls
78 lines (59 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
There are two sisters Alice and Betty. You have 𝑛 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.
*/
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>
using namespace std;
int calculate_distributions(int num_of_candies){
if(num_of_candies==1 || num_of_candies==2){
return 0;
}
// num of candies is odd
if(num_of_candies%2==1){
return num_of_candies/2;
}
// num of candies is even
if(num_of_candies%2==0){
return num_of_candies/2-1;
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int num_test_cases;
cin>>num_test_cases;
for(int i=0; i<num_test_cases; i++){
int n; // number of candies
int result;
cin>>n;
result=calculate_distributions(n);
cout<<result<<"\n";
}
return 0;
}