Sicily 2501. Calculation calculation

Source: Internet
Author: User

2501. Calculation Constraints

Time limit:1 secs, Memory limit:256 MB

Description

_gxx encountered a troublesome equation: S = n 1 + N2 + N3 + ... + NK, known as N, K, for the value of S. Because _GXX maths is poor, I hope you can tell him the answer. But because his math is so bad, you just need to tell him to divide the remainder of s by 9901.

Input

Two integers, N and K (n≤1000, k≤109).

Output

A number that represents the remainder of s divided by 9901.

Sample Input
2 3
Sample Output
14
Problem Source

Huang Jinzhousey--The final sprint of the provincial race

A good mathematical problem, the application of Fermat theorem;

First, by the Fermat theorem, if P is prime, then for number A, there is

Then there are the following two inferences:

1.


2, make Data[i] said

Then there are:


i.e. Data[i] = data[i-1] * n + N; obviously data[1] = n,data[0] = 1; The above 1 indicates that if the value of K is greater than 9901, then n^k = n^ (k-9900), which means that we actually ask for an answer, as long as the preceding 9900 items are calculated You can then put the preceding 9900 items and multiply the number of repetitions (k/9900), plus the number of entries and data[k% 9900]. The code is as follows:
#include <stdio.h> #include <algorithm>using namespace Std;int main () {    int data[9905], n, K;    scanf ("%d%d", &n, &k);    Data[0] = 0;    Data[1] = n;    for (int i = 2; I <= 9900 && i <= K; i++) {        Data[i] = (Data[i-1] * n + N)% 9901;    }    printf ("%d\n", ((data[9900] * (k/9900)) + data[k% 9900])% 9901);    return 0;}

Sicily 2501. Calculation calculation

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.