```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 ``` ```#include #include #include using namespace std; // will loop endlessly if a/b == c/d inline bool greaterOrEqualPositiveFraction(int a,int b,int c,int d); inline bool greaterPositiveFraction(int a,int b,int c,int d); inline bool greaterFraction(int a,int b,int c,int d); inline bool greaterOrEqualPositiveFraction(int a,int b,int c,int d) { if(b == 0) { return true; } if(d == 0) { return false; } if(a*d > b*c) { return true; } if(a*d < b*c) { return false; } return !greaterFraction(b,a%b,d,c%d); } inline bool greaterPositiveFraction(int a,int b,int c,int d) { if(d == 0) { return false; } if(b == 0) { return true; } if(a*d > b*c) { return true; } if(a*d < b*c) { return false; } return !greaterOrEqualPositiveFraction(b,a%b,d,c%d); } inline bool greaterFraction(int a,int b,int c,int d) { if(b<0) { b = -b; a = -a; } if(d<0) { d = -d; c = -c; } if(a<0 && c<0) { return greaterPositiveFraction(-c,d,-a,b); } if(a<0) { return false; } if(c<0) { return true; } return greaterPositiveFraction(a,b,c,d); } char seq[1000005]; int main() { int T; scanf("%d", &T); for(int t=0; t %d/%d\n", i,j,num_pus,num_pyr,max_pus,max_pyr); if(num_pyr==0 && max_pyr==0) { max_pus = max(max_pus,num_pus); } else if(num_pyr==0) { // max sure wins } else if(max_pyr==0) { // num sure wins max_pus = num_pus; max_pyr = num_pyr; } else { // num_pyr!=0, max_pyr!=0 if(max_pus*num_pyr == num_pus*max_pyr) { // take longer sequence if(num_pus+num_pyr > max_pus+max_pyr) { max_pus = num_pus; max_pyr = num_pyr; } } else if(greaterFraction(num_pus,num_pyr,max_pus,max_pyr)) { max_pus = num_pus; max_pyr = num_pyr; } } } } printf("%d %d\n", max_pus,max_pyr); } return 0; } ```