Visible treestime limit:1000msmemory limit:32768kbthis problem'll be judged onHDU. Original id:2841
64-bit integer IO format: %i64d Java class name: Main There is many trees forming a m * n grid, the grid starts from (in). Farmer Sherlock is standing at (0,0) point. He wonders how many trees he can see.
If trees and Sherlock is in one line, Farmer Sherlock can only see the tree nearest to him.InputThe first line contains one integer t, represents the number of test cases. Then there is multiple test cases. For all test case there are one line containing the integers m and $n (1\leq m, N\leq 100000) $OutputFor each test case output one line represents the number of trees Farmer Sherlock can see.Sample Input
21 12 3
Sample Output
15
SourceMulti-university Training Contest 3-host by WHU problem Solving: the principle of tolerance and repulsion
1#include <bits/stdc++.h>2 using namespacestd;3typedefLong LongLL;4 Const intMAXN =200010;5vector<int>G[MAXN];6 voidinit () {7 for(inti =2; i < MAXN; ++i) {8 for(intj =1; I*j < MAXN; ++j)9g[i*J].push_back (i);Ten } One } A intMain () { - intkase,n,m; - init (); thescanf"%d",&Kase); - while(kase--){ -scanf"%d%d",&n,&m); -LL ret =0; + for(inti =2; I <= N; ++i) { - intCNT =0, ans =0; + for(intj =1, T = G[i].size (); J < (1<<T); ++j) { ALL tmp =1; at for(intK = CNT =0; K < T; ++k) { - if((j>>k) &1){ -cnt++; -TMP *=G[i][k]; - } - } in if(cnt&1) ans + = m/tmp; - ElseAns-= m/tmp; to } +RET + = m-ans; - } theprintf"%i64d\n", ret +m); * } $ return 0;Panax Notoginseng}View Code
HDU 2841 Visible Trees