The mathematical problem of "Euler function" Bzoj2190-[sdoi2012]longge

Source: Internet
Author: User

"The main topic"

Find out ∑GCD (i, N) (1<=i <=n).

Ideas

For X=AK,Y=BK, gcd (A, B) =1 must have gcd (x, y) = 1. All factors of the enumeration N, ∑GCD (i, N) =∑ (φ (n/k) *k) (k| N).

*n factor and must be in the n^ (1/2) time to find out, otherwise it will tle.

Code

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6typedefLong Longll;7 /*Note Data range*/8 Const intmaxn=10010;9 ll N;Ten ll FACTOR[MAXN]; One   A voidGet_factor () - /*all quality factors must be calculated within n^ (1/2) time, otherwise te*/ - { theMemset (Factor,0,sizeof(factor)); - ll I; -      for(i=1; i*i<n;i++) -     { +         if(n%i==0) -         { +factor[++factor[0]]=i; Afactor[++factor[0]]=n/i; at         } -     } -     if(i*i==n) factor[++factor[0]]=i; - } -   - ll Eular (ll K) in { -ll res=K; to      for(LL p=2;p *p<=k;p++) +     { -         if(k%p==0) the         { *res=res-res/p; $              while(k%p==0) k/=p;Panax Notoginseng         } -     } the     if(k>1) res=res-res/K; +     /*idea K may be greater than 0 and must be subtracted*/ A     returnRes; the } +   - voidInit () $ { $scanf"%d",&n); - } -   the ll Get_ans () - {Wuyill result=0; the      for(LL i=1; i<=factor[0];i++) -Result+=eular (N/factor[i]) *Factor[i]; Wu     returnresult; - } About   $ intMain () - { - init (); - get_factor (); ACout<<get_ans () <<Endl; +     return 0; the}

The mathematical problem of "Euler function" Bzoj2190-[sdoi2012]longge

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.