Bzoj 2005: [Noi2010] Energy harvesting

Source: Internet
Author: User
Tags gcd

1#include <cstdio>2#include <iostream>3 #definell Long Long4 using namespacestd;5ll f[100009],n,m,ans;6 intMain ()7 {8scanf"%d%d",&n,&m);9     if(n>m)Ten swap (n,m); One      for(inti=n;i;i--) A       { -f[i]= (n/i) * (m/i); -          for(intj=2; j*i<=n;j++) thef[i]-=f[i*j]; -ans+=f[i]* (2*i-1); -       } -printf"%lld\n", ans); +     return 0; -}

There is a conclusion that the number of endpoints on the (x, y) line is equal to GCD (x, y), prove that they are yy, then the problem becomes GCD and, set F[i] for the GCD for I of the number of points, the method can be nlogn in the program to find out.

Bzoj 2005: [Noi2010] 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.