TouchStone
  Please Login
Login Sign Up
 Homepage  Problem Set  Examinations  Submissions  Discussions  Statistics
  • Home
  • Problem Set
  • P3097
  • Problem
  • P3097【伪语法基础】for循环练习2
    Limits : Time Limit : 10000 MS   Memory Limit : 65536 KB
    Description

    给出A,B,C,P四个正整数,计算下面这个式子的值。

    \[ \left( \sum_{k=1}^{A} k^{B}\times C^{k} \right) \texttt{mod}\,P \]
    Input Format

    四个整数A,B,C,P

    Output Format

    一个整数表示答案

    Sample Input

    样例输入1:
    5 5 5 1000000007

    样例输入2:
    123 231 312 1000000009

    Sample Output

    样例输出1:
    10436805

    样例输出2:
    85052265

    Hint

    1<=A<=1018
    0<=B<=2000
    1<=C<=109
    3<=P<=100100100且是质数


    Source  感谢nodgd命题并提供数据