Bzoj 2005 Energy Harvesting

Source: Internet
Author: User

Title Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=36402

Test instructions: On a rectangular ground, plant a kind of energy plant, plants are very neat, there are n columns, each column has M tree, each plant corresponds to a coordinate (x, y). At (0, 0) There is an energy collector, each plant to the energy collector has a loss of energy, if a plant and energy collection machine connected to the line of K plant, then the loss of energy is 2k + 1, if a plant and energy collection machine connected to the line segment without plants, then the energy loss is 1. To seek total energy loss.

Idea: f[d] (x, y) = d the logarithm of the order, then the answer issigma(f[i]*((i-1)*2+1))。分两步来理解这个结论,if gcd(x1, y1) = gcd(x2, y2)那么他们的能量损失一样多(与能量汇集机器连接而成的线段上的植物一样多),再来看看具体的能量损失(也就是如何判断连接线段上的植物有多少棵),那么显然与gcd的值有关,结果就是2 * gcd - 1。

Code

1#include <cstdio>2#include <algorithm>3 using namespacestd;4 5typedefLong LongLL;6 Const intMAXN =100005;7LL F[MAXN];//F[i] Indicates a logarithm that satisfies gcd (x, y) = I (1 <= x <= N, 1 <= y <= m)8 9 intMain ()Ten { One LL N, m; A      while(SCANF ("%lld%lld", &n, &m)! =EOF) { -         if(N >m) Swap (n, m); -LL ans =0; the          for(inti = n; I >=1; --i) { -F[i] = (n/i) * (M/i); -              for(intj = i + i; J <= N; J + =i) { -F[i]-=F[j]; +             } -Ans + = f[i] * (2I1);//all gcd (x, y) = I, resulting in a loss of energy . +         } Aprintf"%lld\n", ans); at     } -     return 0; -}

Bzoj 2005 Energy Harvesting

Related Article

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.