关于大数据考虑不充分可能导致内存越界的问题,程序运行时发生崩溃~求高手解答!
In how many ways can you choose k elements out of n elements, not taking order into account?Write a program to compute this number.
Input Specification
The input file will contain one or more test cases.
Each test case consists of one line containing two integers n () and k ( ).
Input is terminated by two zeroes for n and k.
Output Specification
For each test case, print one line containing the required number. This number will always fit into an integer, i.e. it will be less than 231.
Warning: Don't underestimate the problem. The result will fit into an integer - but if all intermediate results arising during the computation will also fit into an integer depends on your algorithm. The test cases will go to the limit.我的代码如下:#include<iostream>
using namespace std;
long F(int);
int main()
{
int n,k;
while(1)
{
cin>>n>>k;
if(n==0&&k==0) break;
else
cout<<F(n)/(F(k)*F(n-k))<<endl;
}
return 0;
}
long F(int m)
{
int sum=1,i;
for(i=1;i<=m;i++)
sum=sum*i;
return(sum);
}
求高手解答:当我输入49和6之后运行发生崩溃,可能是内存越界了,没有考虑到大数据,该怎么改???急啊~~