1. 程式人生 > >[noip模擬賽]求和(快速冪)

[noip模擬賽]求和(快速冪)

題目描述

1b+2b++ab的和,對10000取模。
多組資料。

T<=100,a,b<=10^9

題解

一個很顯然的性質:ib(i+p)b(modp)
所以只要用快速冪計算出來1b10000b的值然後幾個計算就可以了。

程式碼

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define LL long long
#define Mod 10000

int n;
LL a,b,ans[Mod+5],s[Mod+5],ANS;

inline LL fast_pow(LL a,LL p)
{
    LL ans=1
; for (;p;p>>=1,a=(a*a)%Mod) if (p&1) ans=(ans*a)%Mod; return ans; } int main() { freopen("sum.in","r",stdin); freopen("sum.out","w",stdout); scanf("%d",&n); while (n--) { scanf("%I64d%I64d",&a,&b); for (int i=1;i<=Mod;++i) ans[i]=fast_pow(i,b),s
[i]=(s[i-1]+ans[i])%Mod; LL t=a/Mod; ANS=s[Mod]*t%Mod; t=a%Mod; ANS=(ANS+s[t])%Mod; printf("%I64d\n",ANS); } }

總結

1、打表大法好!
2、遇到數學題不要懵,打表找規律要耐心一些,有一些結論想想就是對的。