nbut 1674

来源:互联网 发布:c语言memset头文件 编辑:程序博客网 时间:2024/05/17 20:50

传送门NBUT 1674

证明:

每一百是一个循环节(好像是20一组)
对于某一个区间[a, a + 99] 100 | a
对于i在[1, 9]
所以尾数为i的数的集合记为s[i]那么
ts[i]ttmod10=0

ts[i]ttmod10=n=09ia+n10+imod10

首先9n=0ia+n10+imod2=0一定成立
其次就是证9n=0ia+n10+imod5=0
若i = 5显然成立;
否则 i 与5互质
根据费马小定理:
i^n 和i ^(n + 20 * k)关于5同余所以可以把 9n=0ia+n10+i分成两组每组五个对5取模模数相同
得证, 因此ts[i]ttmod10=0
代码:

#include <iostream>using namespace std;typedef long long ll;ll n;int cal(int a, int b){    int res = 1;    while(b){        if(b & 1) res = res * a % 10;        a =a * a % 10;        b >>= 1;    }    return res;}int main(){    int t;    cin >> t;    while(t--){        cin >> n;        n %= 100;        int ans = 0;        for(int i = 1; i <= n; ++i) ans = (ans + cal(i, i)) % 10;        cout << ans << endl;    }    return 0;}
0 0
原创粉丝点击