HDU 2841 visible trees)

Source: Internet
Author: User

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2841


There is an N * m square. Starting from (), each vertex has a tree. A person stands at () and asks him how many trees he can see. When (0, 0) and another point are in a straight line, he can only see the nearest one.


The question is to find the number of Y/X types in the square of M * n, because two Y/X points can only see one. The number of types of Y/X is the number of (x, y) X and Y. Where (1 <= x <= m, 1 <= n <= Y ).

In this way, the previous question is similar, and the number of mutual quality numbers with I in a range [1, m] is obtained. Here, 1 <= I <= n. First, find out which is not mutually qualitative with I, and then reject the I factorization quality factor.


# Include <stdio. h> # include <iostream> # include <map> # include <set> # include <bitset> # include <list> # include <stack> # include <vector> # include <math. h> # include <string. h> # include <queue> # include <string> # include <stdlib. h >#include <algorithm> # define ll _ int64 // # define ll long # define EPS 1e-9 # define PI ACOs (-1.0) using namespace STD; const ll INF = 1 <30; const int maxn = 100010; ll ans; int n, m; int FAC [maxn]; int prime [maxn]; int faccnt; void getprime () {bool flag [maxn]; memset (flag, false, sizeof (FLAG); prime [0] = 0; For (INT I = 2; I <maxn; I ++) {If (flag [I] = false) prime [++ prime [0] = I; for (Int J = 1; j <= prime [0] & I * prime [J] <maxn; j ++) {flag [I * prime [J] = true; if (I % prime [J] = 0) Break ;}} void getfac (INT num) {int TMP = num; faccnt = 0; For (INT I = 1; I <= prime [0] & prime [I] * prime [I] <= TMP; I ++) {If (TMP % prime [I] = 0) {FAC [faccnt ++] = prime [I]; while (TMP % prime [I] = 0) tmp/= prime [I];} if (TMP = 1) break;} If (TMP> 1) FAC [faccnt ++] = TMP;} ll solve (INT m) {// queue array int que [110]; int L = 0; que [L ++] = 1; for (INT I = 0; I <faccnt; I ++) {int K = L; For (Int J = 0; j <K; j ++) que [L ++] = FAC [I] * que [J] * (-1);} ll ANW = 0; For (INT I = 0; I <L; I ++) ANW + = m/que [I]; return ANW;} int main () {int test; scanf ("% d", & test ); getprime (); For (INT item = 1; item <= test; item ++) {scanf ("% d", & N, & M ); if (n> m) Swap (n, m); ans = 0; For (INT I = 1; I <= N; I ++) {getfac (I ); ans + = solve (m);} printf ("% i64d \ n", ANS);} return 0 ;}




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.