import java.io.PrintStream; import java.util.Arrays; import java.util.Scanner; /** * Solution to Spidey Distance * * @author vanb */ public class spidey_vanb { /** Input. */ private static Scanner sc; /** Output. */ private static PrintStream ps; /** * Do it! */ private void doit() { int t = sc.nextInt(); int s = sc.nextInt(); // Doubling s will be useful. // A diagonal will cost 3 and a horizontal or vertical will cost 2. // This way we can keep it all in integers. int s2 = s+s; // Minimum of s and t will also be useful int minst = Math.min( s, t ); // Assume we're starting from (0,0). // We'll only count the upper right quadrant, not including the axes. // We'll need to keep track of each row, because the taxi-cab distance can't go beyond the spidey distance. int rows[] = new int[s]; Arrays.fill( rows, 0 ); // We'll just trace the diagonals. // Remember, each diagonal step costs 3 in our doubled world. for( int i=1; 3*i<=s2; i++ ) { // This is how far out we can go after taking i diagonal steps. int len = i + (s2-i*3)/2; rows[i] = len; // We'll take advantage of the fact that the quadrant shape is symmetrical around the diagonal. // If rows[i]=len, then rows[len]=i. The same row can be hit twice, we'll take the max. if( i>rows[len] ) rows[len] = i; } long spideyCount = 0; for( int len : rows ) spideyCount += len; // Our final count is 4*quadrant + 4*axis + the origin spideyCount = 4*(spideyCount+s) + 1; // Same logic for the taxi-cab distance. // It's a lot simpler, but we have to make sure we don't go outside of the spidey distance area. long taxiCount = 0; for( int i=1; i0 ) { a = b; b = r; r = a%b; } taxiCount /= b; spideyCount /= b; // Output is a little messy ps.println( spideyCount==1 ? (""+taxiCount) : (taxiCount + "/" + spideyCount) ); } /** * Main. * * @param args unused * @throws Exception */ public static void main( String[] args ) throws Exception { sc = new Scanner( System.in ); ps = System.out; new spidey_vanb().doit(); } }