Question link: 1393-Highways question: given an n * m dot matrix, I would like to ask how many lines can be formed after the two links pass through at least two vertices, and it is not a horizontal or vertical idea: I have found a line segment of two points. Because it is an integer coordinate, as long as the slope is not an integer, that is, x/y is not an integer, it can satisfy the answer, and then record all the positions first, then, we can use the volume rejection principle to find the number of such line segments that can be connected to each vertex. Finally, we need to sum them. Note that some of them are repeated computations, for example, if 1 and 2 are connected, 2, 2, and 3 are connected, this is actually a piece of information, so the duplicate part should be deducted at the end of the sum, subtract sum [I/2] [j/2] directly, because the code that still exists after narrowing down twice will certainly be repeated:
# Include
# Include
Int n, m; long dp [305] [305], ans [305] [305]; int gcd (int a, int B) {if (B = 0) return a; return gcd (B, a % B);} int main () {for (int I = 1; I <= 300; I ++) for (int j = 1; j <= 300; j ++) dp [I] [j] = dp [I-1] [j] + dp [I] [j-1]-dp [I-1] [j-1] + (gcd (I, j) = 1); for (int I = 1; I <= 300; I ++) for (int j = 1; j <= 300; j ++) ans [I] [j] = ans [I-1] [j] + ans [I] [j-1]-ans [I-1] [j-1] + dp [I] [j]-dp [I /2] [j/2]; while (~ Scanf ("% d", & n, & m) & n | m) {printf ("% lld \ n ", ans [n-1] [m-1] * 2);} return 0 ;}