大数板子有错, 被逼无奈写了java
import java. io. *;
import java. math. BigInteger;
import java. util. *;
public class Main
{
int prime ( int x) {
for ( int i = 2 ; i * i <= x ; ++ i) {
if ( x % i == 0 ) return 0 ;
}
return 1 ;
}
public static void main ( String[ ] args)
{
int p[ ] = new int [ 150 ] ;
int cnt = 0 ;
for ( int i = 5 ; ; ++ i) {
int flag = 0 ;
for ( int j = 2 ; j * j <= i ; ++ j) {
if ( i % j == 0 ) { flag = 1 ; break ; }
}
if ( flag != 1 ) {
p[ ++ cnt] = i;
if ( cnt == 100 ) break ;
}
}
Scanner in= new Scanner ( System. in) ;
int n;
n = in. nextInt ( ) ;
for ( int pp = 1 ; pp <= n ; pp ++ )
{
BigInteger x;
x = in. nextBigInteger ( ) ;
if ( x. compareTo ( BigInteger. valueOf ( 1 ) ) == 0 ) {
System. out. print ( "1" ) ;
System. out. print ( "/" ) ;
System. out. print ( "1" ) ;
System. out. println ( "" ) ;
continue ;
}
else if ( x. compareTo ( BigInteger. valueOf ( 2 ) ) == 0 ) {
System. out. print ( "2" ) ;
System. out. print ( "/" ) ;
System. out. print ( "3" ) ;
System. out. println ( "" ) ; continue ;
}
else if ( x. compareTo ( BigInteger. valueOf ( 3 ) ) == 0 ) {
System. out. print ( "2" ) ;
System. out. print ( "/" ) ;
System. out. print ( "3" ) ;
System. out. println ( "" ) ; continue ;
}
else if ( x. compareTo ( BigInteger. valueOf ( 4 ) ) == 0 ) {
System. out. print ( "2" ) ;
System. out. print ( "/" ) ;
System. out. print ( "3" ) ;
System. out. println ( "" ) ; continue ;
}
else if ( x. compareTo ( BigInteger. valueOf ( 5 ) ) == 0 ) {
System. out. print ( "2" ) ;
System. out. print ( "/" ) ;
System. out. print ( "3" ) ;
System. out. println ( "" ) ; continue ;
}
BigInteger a= BigInteger. valueOf ( 1 ) ;
BigInteger b= BigInteger. valueOf ( 2 ) ;
BigInteger c= BigInteger. valueOf ( 6 ) ;
BigInteger y= BigInteger. valueOf ( 1 ) ;
for ( int i = 1 ; ; ++ i) {
BigInteger temp = c. multiply ( BigInteger. valueOf ( p[ i] ) ) ;
if ( temp. compareTo ( x) == 1 ) {
y = a. gcd ( b) ;
a = a. divide ( y) ; b = b. divide ( y) ;
System. out. print ( a) ;
System. out. print ( "/" ) ;
System. out. print ( b) ;
System. out. println ( "" ) ;
break ;
}
c= c. multiply ( BigInteger. valueOf ( p[ i] ) ) ;
a= a. multiply ( BigInteger. valueOf ( p[ i] ) ) ; b= b. multiply ( BigInteger. valueOf ( p[ i] + 1 ) ) ;
}
}
}
}