tjut 4873

来源:互联网 发布:美国类似知乎的网站 编辑:程序博客网 时间:2024/06/05 23:57
#include <cstdio>  #include <cstring>  #include <algorithm>  #include <time.h>  #include <stdlib.h>  using namespace std ;    #define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )  #define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )  #define REPV( i , a , b ) for ( int i = a ; i >= b ; -- i )  #define CLR( a , x ) memset ( a , x , sizeof a )    typedef long long LL ;    const int MAXN = 30005 ;  const int MAXE = 200000 ;  const int MAXQ = 200000 ;  const int INF = 0x3f3f3f3f ;  const int TOP = 1000000000 ;    int N , D ;  LL a[MAXN] ;    int gcd ( int a , int b ) {      return a ? gcd ( b % a , a ) : b ;  }    void print ( int A[] , int B[] , int only_one ) {      int top ;      top = 0 ;      CLR ( a , 0 ) ;      a[0] = 1 ;      REP ( i , 4 ) {          REPF ( j , 0 , top ) {              a[j] *= A[i] ;              if ( j && a[j - 1] >= TOP ) {                  a[j] += a[j - 1] / TOP ;                  a[j - 1] %= TOP ;              }              if ( a[top] >= TOP )                  ++ top ;          }      }      printf ( "%d" , ( int ) a[top] ) ;      -- top ;      REPV ( i , top , 0 )          printf ( "%09d" , ( int ) a[i] ) ;      if ( only_one ) {          printf ( "\n" ) ;          return ;      }      //---------------------      printf ( "/" ) ;      //---------------------      top = 0 ;      CLR ( a , 0 ) ;      a[0] = 1 ;      REPF ( i , 0 , D ) {          REPF ( j , 0 , top ) {              a[j] *= B[i] ;              if ( j && a[j - 1] >= TOP ) {                  a[j] += a[j - 1] / TOP ;                  a[j - 1] %= TOP ;              }              if ( a[top] >= TOP )                  ++ top ;          }      }      printf ( "%d" , ( int ) a[top] ) ;      -- top ;      REPV ( i , top , 0 )          printf ( "%09d" , ( int ) a[i] ) ;      printf ( "\n" ) ;  }    void solve () {      if ( D == 1 ) {          printf ( "%d\n" , 0 ) ;          return ;      }      int A[4] = { N + 4 , N + 4 , D , D - 1 } ;      int B[100] = { 18 } ;      int tmp ;      REPF ( i , 1 , D )          B[i] = N ;      REP ( i , 4 )          REPF ( j , 0 , D )              if ( ( tmp = gcd ( A[i] , B[j] ) ) > 1 )                  A[i] /= tmp , B[j] /= tmp ;      int only_one = 1 ;      REPF ( i , 0 , D )          if ( B[i] != 1 )              only_one = 0 ;      print ( A , B , only_one ) ;  }          int main () {      while ( ~scanf ( "%d%d" , &N , &D ) )          solve () ;      return 0 ;  }  


0 0