找到将数字分为四部分的方法数量,以使C ++中的a = c和b = d
假设我们有一个数字n。我们必须找到多种方法将数字分为几部分(a,b,c和d),使得a=c,b=d。因此,如果数字为20,则输出将为4。如[1、1、9、9],[2、2、8、8],[3、3、7、7]和[4、4、6,6]
因此,如果N为奇数,则答案将为0。如果数字可被4整除,则答案将为n/4–1,否则为n/4。
示例
#include <iostream>
using namespace std;
int countPossiblity(int num) {
if (num % 2 == 1)
return 0;
else if (num % 4 == 0)
return num / 4 - 1;
else
return num / 4;
}
int main() {
int n = 20;
cout << "Number of possibilities: " << countPossiblity(n);
}输出结果
Number of possibilities: 4
热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短