2501. 算算式

来源:互联网 发布:分类算法应用场景 编辑:程序博客网 时间:2024/04/25 23:06

2501. 算算式

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

_gXX遇到一个麻烦的式子:

S = n1 + n2 + n3 + ...... + nk,已知nk,求S的值。

因为_gXX数学很差,希望你能告诉他答案。但是由于他的数学实在太差了,所以你只需要告诉他S除以9901的余数即可。

Input

两个整数,nkn ≤ 1000 , k ≤ 109)。

Output

一个数,表示S除以9901的余数。

Sample Input

2 3

Sample Output

14

Problem Source

黄金周赛——省赛最后的冲刺

费马小定理,算法参考

http://blog.csdn.net/luojiayu14/article/details/7089499

http://www.doc88.com/p-381740859897.html

// Problem#: 2501

// Submission#: 1986692

// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/

// All Copyright reserved by Informatic Lab of Sun Yat-sen University

#include<iostream>

#include<cmath>

using namespace std;

int main(){

    int n,k,i,sum=0;    

    cin>>n>>k;

    k%=9900;

    for(i=1;i<=k;i++){

        sum=(sum+1)*n;

        sum%=9901;

    }

    cout<<sum<<endl;

    return 0;

}