HDU 4335 What is N? Simple Number Theory

Source: Internet
Author: User

This is a simple formula.

A ^ x % c = a ^ (x % phi (c) + phi (c) % c where x> = phi (c)
Phi (c) is the Euler's function.
Note that the Euler function is defined as the number of positive integers not greater than n and with n, instead of less than n.
And phi (1) = 1

This question is divided into three parts:
Part 1 n! <Phi (c) Then you need to calculate n directly! Fortunately, phi (c) is not very large.
Part 2 n! > = Phi (c) but n! % Phi (c )! = 0 this part also requires brute-force computation, but the modulo operation can be performed without a very large number.
Part 3 n! > = Phi (c) and n! % Phi (c) = 0 is converted to n ^ phi (c) % c and then (n % c) ^ phi (c) % c is a loop section with the length of c.

In the end, it is important to note that the question has a large scope and requires uLL, and the answer may exceed uLL, because when c = 1, B = 0, 0 to 2 ^ 64-1 are all qualified, so special judgment is required.
The code is not given, and it is not difficult to write.


Author: sdj222555

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.