1248:HH Military Training Time limit: 1 Sec Memory Limit: MB
Submit: Solved: 8
[Submit] [Status] [Web Board] [Edit] Description
University, the most memorable thing is military training, white HH children's shoes are ruthless tanning, saying that during military training, the most feared is to be instructors tease, as the saying goes: Cherish life, away from instructors. Instructors always love to let students stand square, because a lot of classmates, will inevitably have the students in front of the students in the back, in order to stay away from the instructor, we all hope that their position instructor can not see themselves, now if the students stand in a coordinate point of the matrix, the students are standing in each group of integers, and the instructor standing in the coordinates Please tell me how many positions instructors can see directly at this time!
Input
The first line enters a T, which represents the T-group test data.
Next, enter two digital m,n per line, and for any one of the students coordinate position (x, y), there are 1<=x<=m<=10000,1<=y<=n<=10000.
Output
Output How many positions instructors can see.
Sample Input2 1 4) 2 3Sample Output4 5HINT
For the test Data 2 3, at this time because the position (2,2) is blocked, so there is a position instructor can not see, so there are 5 positions instructors could directly see
Source
The fifth annual ACM Program Design Competition of Henan Polytechnic University
The template problem of the tolerant principle.
#include <stdio.h> #include <string.h> int p[12], que[1024], K, back; void Getp (int n) {int I, j, t; k = 0; for (i = 2; I * I <= n; ++i) if (n% i = = 0) {p[k++] = i; while (n% i = = 0) n/= i; } if (n > 1) p[k++] = n; back = 0; que[back++] =-1; for (i = 0; i < K; ++i) {t = back; for (j = 0; j < T; ++j) que[back++] = p[i] * QUE[J] *-1; }} int nop (int m) {int sum = 0, I; for (i = 1; i < back; ++i) sum + = M/que[i]; return sum; } int main () {int T, m, N, I, ans; scanf ("%d", &t); while (t--) {scanf ("%d%d", &n, &m); ans = n; for (i = 2; I <= m; ++i) {GETP (i); Ans + = N-NOP (n); } printf ("%d\n", ans); } return 0; }/************************************************************** problem:1248 User:changmu language:c++ result:accepted time:820 Ms memory:820 KB ****************************************************************/
HPU1248:HH's military training "the principle of tolerance and repulsion"