Nyoj 928 small M factor and (number theory)

Source: Internet
Author: User
Small M factor and time limit: 1000 MS | memory limit: 65535 kb difficulty: 2
Description

When he was in class, Mr. M was a bit out of his mind, and the teacher was hard on his question. I heard that Mr. M is still very proud of finding the factor and the power of B. But after reading the question, I want to find the factor and the power of B. I am a little confused. Can you solve this problem?

Input
Multiple groups of test examples
Each row has two numbers a, B, (1 ≤ a, B ≤ 10 ^ 9)
Output
Output the factor and of B power of A, and take the remainder of 9901.
Sample Input
2 3
Sample output
15


Analysis: Perform prime factor decomposition for A. Assume that a = (P1 ^ A1) * (P2 ^ A2 )*...... * (Pk ^ AK), assuming the factor of A is sum,

Then sum = (1 + p1 + p1 ^ 2 + ...... + P1 ^ A1) * (1 + p2 + p2 ^ 2 + ...... + P2 ^ A2 )*...... * (1 + PK ^ 2 + ...... + PK ^ AK). After this formula is expanded, each item is a factor.

Therefore, for the factor and time of a ^ B, you only need to change AI to ai * B and then solve the problem. Because the power is relatively large, it needs to be obtained through sub-governance and quick power.

# Include <cstdio> # include <cmath> const int mod = 9901; int POW (int A, int N) {// fast power a ^ n int res = 1; A % = MOD; while (n) {If (N & 1) RES = res * A % MOD; A = A * A % MOD; n >>= 1 ;} return res;} int get_sum (int A, int N) {// evaluate (1 + A ^ 2 + ...... + A ^ N) if (n = 0) return 1; if (N & 1) return get_sum (A, n/2) * (POW (, (n/2 + 1) + 1) % MOD; else return (get_sum (A, n/2-1) * (POW (A, n/2) + 1) + POW (A, n) % MOD;} int main () {int A, B; while (~ Scanf ("% d", & A, & B) {int ans = 1; int M = (INT) SQRT (a + 0.5 ); for (INT I = 2; I <= m; ++ I) {if (a % I = 0) {int K = 0; while (a % I = 0) {k ++; A/= I;} ans = ans * get_sum (I, K * B) % mod ;}} if (A> 1) ans = ans * get_sum (a, B) % MOD; printf ("% d \ n", ANS);} return 0 ;}


Nyoj 928 small M factor and (number theory)

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.