bzoj 3142 数学

时间:2023-12-13 10:55:20

找规律后可以之后答案就是

k^(m-1)*(n-(m-1)*k)+(m+(m-1)*k+1)*k^(m-1) div 2

/**************************************************************
    Problem:
    User: BLADEVIL
    Language: Pascal
    Result: Accepted
    Time: ms
    Memory: kb
****************************************************************/
 
//By BLADEVIL
var
    n, m                    :int64;
    k, p, x                 :int64;
     
function mi(a,b:int64):int64;
var
    sum, ans                :int64;
begin
    sum:=a; ans:=;
    while b> do
    begin
        if b mod = then ans:=ans*sum mod p;
        sum:=sum*sum mod p;
        b:=b div ;
    end;
    exit(ans);
end;
begin
    readln(n,k,m,p);
    dec(k);
    x:=mi(m,k-);
    writeln(int64(n mod p*m-m*(m+) div mod p*k+p*) mod p*x mod p);
end.