找到将数字分为四部分的方法数量,以使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 好听的元旦简短祝福语