標籤:
題目連結:點擊開啟連結
百度個題解:點擊開啟連結
6的因子是1,2,3,6; 6的因子和是 s(6)=1+2+3+6=12;
20的因子是1,2,4,5,10,20; 20的因子和是 s(20)=1+2+4+5+10+20=42;
2的因子是1,2; 2的因子和是 s(2)=1+2=3;
3的因子是1,3; 3的因子和是 s(3)=1+3=4;
4的因子和是 s(4)=1+2+4=7;
5的因子和是 s(5)=1+5=6;
s(6)=s(2)*s(3)=3*4=12;
s(20)=s(4)*s(5)=7*6=42;
這是巧合嗎?
再看 s(50)= 1+2+5+10+25+50=93=3*31=s(2)*s(25),s(25)=1+5+25=31.
這在數論中叫積性函數,當gcd(a,b)=1時 s(a*b)=s(a)*s(b);
如果p是素數
s(p^n)=1+p+p^2+...+p^n= (p^(n+1)-1) /(p-1) (1)
例 hdu1452 Happy 2004
計算 因子和 s(2004^X) mod 29 ,
2004=2^2 *3 *167
s(2004^X) ) = (s(2^2X))) * (s(3^X))) * (s(167^X)))
167)=22;
s(2004^X) ) = (s(2^2X))) * (s(3^X))) * (s(22^X)))
a=s(2^2X)=(2^(2X+1)-1) //根據 (1)
b=s(3^X)= (3^(X+1)-1)/2 //根據 (1)
c=s(22^X)= (22^(X+1)-1)/21 //根據 (1)
%運演算法則 1. (a*b) %p= ( a%p) *(b%p)
%運演算法則 2. (a/b) %p= ( a *b^(-1)%p)
b^(-1)是 b的逆元素 (%p)
2的逆元素是15 ()) ,因為2*15=30 % 29=1 % 29
21的逆元素是18 ()) ,因為21*18=378% 29 =1 % 29
因此
a=(powi(2,2*x+1,29)-1)% 29;
b=(powi(3,x+1,29)-1)*15 % 29;
c=(powi(22,x+1,29)-1)*18 % 29;
ans=(a*b)% 29*c % 29;
#include <stdio.h>#include <iostream>#include <algorithm>#include <sstream>#include <stdlib.h>#include <string.h>#include <limits.h>#include <vector>#include <string>#include <time.h>#include <math.h>#include <iomanip>#include <queue>#include <stack>#include <set>#include <map>const int inf = 1e8;const double eps = 1e-8;const double pi = acos(-1.0);template <class T>inline bool rd(T &ret) {char c; int sgn;if (c = getchar(), c == EOF) return 0;while (c != '-' && (c<'0' || c>'9')) c = getchar();sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');ret *= sgn;return 1;}template <class T>inline void pt(T x) {if (x <0) { putchar('-'); x = -x; }if (x>9) pt(x / 10);putchar(x % 10 + '0');}using namespace std;const int mod = 29;int Pow(int x, int y){int ans = 1;while (y){if (y & 1)ans = ans*x%mod;y >>= 1;x = x*x%mod;}return ans;}int n;//2004= 2*2*3*167int gao(int x, int y){int ans = Pow(x, y + 1) - 1;while (ans % (x - 1))ans += mod;ans /= x - 1;return ans%mod;}int main(){while (cin>>n, n){int ans = gao(2, 2 * n) * gao(3, n) * gao(167, n);cout << ans % mod<< endl;}return 0;}
HDU 1452 Happy 2004 求2004^n的所有因子和 積性函數應用