Hangzhou Electric acm1286--to find new friend ~ Euler function application

Source: Internet
Author: User

Euler functions

Euler functions, for positive integer n, the Euler function is the number of the number of n coprime less than or equal to N.

The general formula is:

F (x) = x * (1-1/p1) * (1-1/p2) * ... * (1-1/PN); P1,p2,p3.....pn is the qualitative factor of X. Each quality factor occurs only once. that is p1≠p2≠....pn; for example 12 = 2 * 2 * 3;2 can only be counted once.

With this Oraton-type, you can quickly solve the problem, the beginning I was done in a normal way, it is obvious that the time-out, a number of input at a time, it is easy to time out.

The following is the code for AC:

#include <iostream>using namespace std; #define MAX 33000int a[max];void make_eular ()             //Hit table {a[1] = 1;for (int i = 2 ; i < MAX; i++) {A[i] = i;} for (int j = 2; J < Max; J + +)         //For each Euler function, {if (a[j] = = j) {for (int k = j; k < Max; k + + j)//  from J to MAX, each number, a qualitative factor of K of J, calculated once. Plus the outer loop, the J layer, calculates the Euler function {//For each number                                . A[K] = a[k]/J * (J-1);}}} int main () {int n, t;make_eular (), CIN >> T;while (t--) {cin >> n;cout << a[n] << Endl;} return 0;}


Hangzhou Electric acm1286--to find new friend ~ Euler function application

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.