#2791: 本機跑的出答案但是上傳就RE


zxm20243 (zxm20243)

學校 : 國立臺灣大學
編號 : 8385
來源 : [111.243.94.71]
最後登入時間 :
2017-07-14 20:31:22
d134. 00369 - Combinations -- UVa369 | From: [140.112.241.247] | 發表日期 : 2009-11-20 07:46

如題

#include <stdio.h>

int main( void )
{
 int m, n;
 while( 1 )
 {
  unsigned long long int a, b;
  unsigned long long int ans = 1;

  scanf( "%llu%llu", &n, &m );
  a = n;
  b = m;

  if( n - m < m )
  m = n - m;

  if( n == 0 && m == 0 )
  break;

  else if( m == 1 )
  printf( "%llu things taken %llu at a time is %llu exactly.\n", a, b, a );

  else if( m == 0 )
  printf( "%llu things taken %llu at a time is 1 exactly.\n", a, b );
  
  else
  {
   int i, j = 2;
   for( i = n-m+1; i <= n; i++ )
   {
    ans *= i;

    while( ans % m == 0 )
    {
     ans /= m;
     m--;
    }

    while( ( j <= m ) && ( ans % j == 0 ) )
    {
     ans /= j;
     j++;
    }

   }
  }

  printf( "%llu things taken %llu at a time is %llu exactly.\n", a, b, ans );
 }

return 0;
}

 

 
ZeroJudge Forum