import java.io.*; import java.util.*; import java.awt.geom.*; /** * Solution to Primal Partitions * * @author vanb */ public class primal_fast_vanb { public Scanner sc; public PrintStream ps; /** This is an array of all of the primes <1000 */ public static int primes[] = new int[168]; /** * Generate all of the primes <1000 */ public static void generatePrimes() { boolean isprime[] = new boolean[1001]; Arrays.fill( isprime, true ); isprime[0] = false; isprime[1] = false; int index = 0; for( int i=0; i1; j++ ) { int p = primes[j]; if( value%p==0 ) { biggestprime[i] = p; while( value%p==0 ) value /= p; } } if( value>1 ) biggestprime[i] = i; } int n = sc.nextInt(); int k = sc.nextInt(); int sequence[] = new int[n]; for( int i=0; i0 ) { bestset = gcd( sets[i-1][j], sequence[i] ); bestscore = Math.min( smallest[i-1][j], biggestprime[bestset] ); } if( sets[i-1][j-1]>0 ) { int score = Math.min( smallest[i-1][j-1], biggestprime[sequence[i]] ); if( score > bestscore || bestset==0 ) { bestscore = score; bestset = sequence[i]; } } //if( bestscore==31 ) System.err.println( i + " " + j ); smallest[i][j] = bestscore; sets[i][j] = bestset; } } ps.println( smallest[n-1][k] ); } /** * @param args */ public static void main( String[] args ) throws Exception { new primal_fast_vanb().doit(); } }