HDU 2841 Visible Trees

Source: Internet
Author: User

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&LT;&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.