Re: 530 Why WA
Posted: Mon Aug 16, 2010 6:41 am
variable is short.
Code: Select all
#include <math.h>
int main()
{
long long n,k;
while(scanf("%lld %lld",&n,&k)==2)
{
long long num=1,d=1,i,a;
if(n==0 && k==0) break;
long long min = n - k;
for(i=n; i > min; i--)
num = num * i;
for(i=k; i > 1; i--)
d = d * i;
a = num/d;
printf("%lld\n",a);
}
return 0;
}
yes you did. thanx a lot.avatar wrote:for those who are getting WA try the following:::::
[/c]
input::::
45 0
15 9
0 0
output::::
1
5005
hope i helped u
Code: Select all
#include <cstdio>
#include <cctype>
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
long double n, m;
while(scanf("%Lf %Lf",&n,&m)==2)
{
long double t=0.0, t_fact=1.0, m_fact=1.0, n_fact=1.0, c, i, j;
if(n==0 && m==0) break;
if(m==1)
cout<<n<<endl;
else if(m==0) cout<<"1"<<endl;
else
{
t=n-m;
if(t>m)
{
for(i=n ; i>t ; i--)
{
n_fact=n_fact*i;
if(m>0)
{
n_fact/=m;
m--;
}
}
c=n_fact;
//m=m+1.0;
if(m>1)
{
for(j=m ; j>=1 ; j--)
m_fact*=j;
c=n_fact/m_fact;
}
}
else
{
for(i=n ; i>m ; i--)
{
n_fact*=i;
if(t>0)
{
n_fact/=t;
t--;
}
}
c=n_fact;
//t=t+1.0;
if(t>1)
{
for(j=t ; j>0 ; j--)
t_fact*=j;
c=n_fact/t_fact;
}
}
printf("%.0Lf\n",c);
}
}
return 0;
}
Code: Select all
#include <cstdio>
#include <cctype>
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
unsigned long long n, m;
while(scanf("%llu %llu",&n,&m)==2)
{
unsigned long long t=0, t_fact=1, m_fact=1, n_fact=1, c, i, j;
if(n==0 && m==0) break;
if(m==1)
cout<<n<<endl;
else if(m==0) cout<<"1"<<endl;
else
{
t=n-m;
if(t>m)
{
for(i=n ; i>t ; i--)
{
n_fact=n_fact*i;
if(m>0)
{
n_fact/=m;
m--;
}
}
c=n_fact;
//m=m+1.0;
if(m>1)
{
for(j=m ; j>=1 ; j--)
m_fact*=j;
c=n_fact/m_fact;
}
}
else
{
for(i=n ; i>m ; i--)
{
n_fact*=i;
if(t>0)
{
n_fact/=t;
t--;
}
}
c=n_fact;
//t=t+1.0;
if(t>1)
{
for(j=t ; j>0 ; j--)
t_fact*=j;
c=n_fact/t_fact;
}
}
printf("%llu\n",c);
}
}
return 0;
}
Code: Select all
Finally, I got it AC /* Removed */
Code: Select all
33 33
33 32
33 31
33 30
33 29
33 28
33 27
33 26
33 25
33 24
33 23
33 22
33 21
33 20
33 19
33 18
33 17
0 0
Code: Select all
1
33
528
5456
40920
237336
1107568
4272048
13884156
38567100
92561040
193536720
354817320
573166440
818809200
1037158320
1166803110
Code: Select all
removed after AC