【问题标题】:How to get all possible combinations of the number if we have divide the number in equal number of groups如果我们将数字分成相等数量的组,如何获得数字的所有可能组合
【发布时间】:2021-09-08 23:38:39
【问题描述】:

假设我们有 6 个气球。我们只能按如下方式进行分组:

  1. 每组3个气球一组:共2组
  2. 每组2个气球一组:共3组
  3. 一组,每组1个气球:共6组

假设我们有 10 个气球。我们只能按如下方式进行分组:

  1. 每组5个气球一组:共2组
  2. 每组2个气球一组:共5组
  3. 一组,每组1个气球:共10组

我无法为其编写 C 语言代码。

【问题讨论】:

  • 您只需要上到平方根 - 每个因子给出互补因子 >= 平方根。

标签: c algorithm data-structures


【解决方案1】:

使用此代码,您将能够显示您的号码的所有除数:

int main()
{
long int n,i;
cout<<"Enter the number: ";
cin>>n;
cout<<endl<<"Divisors of "<<n<<" are";

for(i=1;i<=n;++i)
{
if(n%i==0)
cout<<" "<<i;
}

return 0;
}

【讨论】:

  • 在标记的 C...?
猜你喜欢
  • 1970-01-01
  • 2016-08-09
  • 1970-01-01
  • 1970-01-01
  • 2019-10-25
  • 2013-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多