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
- tjut 4873
- tjut 5289
- tjut 5288
- tjut 5294
- tjut 2586
- tjut 5296
- tjut 5297
- tjut 5299
- tjut 5384
- tjut 5387
- tjut 5386
- tjut 5381
- tjut 5400
- tjut 5399
- tjut 5396
- tjut 5398
- tjut 5412
- tjut 5410
- Codeforces 699D
- Java开发的几个注意点
- JAVA 面向对象 隐藏和封装
- ASP.NET/MVC 配置log4net启用写错误日志功能
- Spark简要学习
- tjut 4873
- 对Linux目录和文件系统的理解
- 3.2.6工作集
- Xcode运行卡,怎么办
- Maven实战(二)--setting.xml详解
- 我的C语言笔记1
- [GitHub开源]Android自定义View实现微信打飞机游戏
- Activity中使用handle存在内存泄漏的隐患
- linux课堂笔记--shell4正则表达式