日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Sumdiv POJ - 1845

發布時間:2023/12/3 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Sumdiv POJ - 1845 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Sumdiv POJ - 1845

題意:

ABA^BAB的所有約數之和mod 9901(1<=A,B<=5e7)

題解:

我們先將A分解質因子,表示為:p1c1?p2c2?......?pncnp_{1}^{c_{1}}*p_{2}^{c_{2}}*......*p_{n}^{c_{n}}p1c1???p2c2???......?pncn??
約數之和我們是有公式的:
A的約數和是:(1+p1+p12+....+p1c1)?....?(1+pn+pn2+....+pncn)(1+p_{1}+p_{1}^2+....+p_{1}^{c_{1}})*....*(1+p_{n}+p_{n}^2+....+p_{n}^{c_{n}})(1+p1?+p12?+....+p1c1??)?....?(1+pn?+pn2?+....+pncn??)
ABA^BAB的所有約數之和為:
(1+p1+p12+....+p1B?c1)?....?(1+pn+pn2+....+pnB?cn)(1+p_{1}+p_{1}^2+....+p_{1}^{B*c_{1}})*....*(1+p_{n}+p_{n}^2+....+p_{n}^{B*c_{n}})(1+p1?+p12?+....+p1B?c1??)?....?(1+pn?+pn2?+....+pnB?cn??)
不難發現,每一項都是一個等比序列,我們用等比序列求和,(1+p1+p12+....+p1B?c1)=(p1B?c1+1?1)/(p1?1)(1+p_{1}+p_{1}^2+....+p_{1}^{B*c_{1}})=(p_{1}^{B*c_{1}+1}-1)/(p_{1}-1)(1+p1?+p12?+....+p1B?c1??)=(p1B?c1?+1??1)/(p1??1)
對于分子分母我們分開求,用快速冪求即可,分母逆元
但是這樣并沒有結束,什么時候b的逆元是bp?2b^{p-2}bp?2,當p是質數且b與m互質時,本題中9901是質數,但是p1?1p_{1}-1p1??1有可能是9901的倍數,此時乘法逆元就不存在。這種情況特判,此時(1+p1+p12+....+p1B?c1)≡1+1+12+...+1B?c1≡B?c1+1(mod9901)(1+p_{1}+p_{1}^2+....+p_{1}^{B*c_{1}})\equiv 1+1+1^2+...+1^{B*c_{1}}\equiv B*c_{1}+1(\bmod 9901)(1+p1?+p12?+....+p1B?c1??)1+1+12+...+1B?c1?B?c1?+1(mod9901)

代碼:

// Problem: Sumdiv // Contest: Virtual Judge - POJ // URL: https://vjudge.net/problem/POJ-1845 // Memory Limit: 30 MB // Time Limit: 1000 ms // Data:2021-08-26 14:17:14 // By Jozky#include <cmath> #include <cstdio> #include <ctime> #include <iostream> // #include <unordered_map> #define debug(a, b) printf("%s = %d\n", a, b); using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> PII; clock_t startTime, endTime; //Fe~Jozky const ll INF_ll= 1e18; const int INF_int= 0x3f3f3f3f; void read(){}; template <typename _Tp, typename... _Tps> void read(_Tp& x, _Tps&... Ar) {x= 0;char c= getchar();bool flag= 0;while (c < '0' || c > '9')flag|= (c == '-'), c= getchar();while (c >= '0' && c <= '9')x= (x << 3) + (x << 1) + (c ^ 48), c= getchar();if (flag)x= -x;read(Ar...); } template <typename T> inline void write(T x) {if (x < 0) {x= ~(x - 1);putchar('-');}if (x > 9)write(x / 10);putchar(x % 10 + '0'); } void rd_test() { #ifdef LOCALstartTime= clock();freopen("in.txt", "r", stdin); #endif } void Time_test() { #ifdef LOCALendTime= clock();printf("\nRun Time:%lfs\n", (double)(endTime - startTime) / CLOCKS_PER_SEC); #endif } int a, b, m, ans= 1; const int mod= 9901; int p[20], c[20]; void divide(int n) {m= 0;for (int i= 2; i <= sqrt(n); i++) {if (n % i == 0) {p[++m]= i;c[m]= 0;while (n % i == 0) {n/= i;c[m]++;}}}if (n > 1) {p[++m]= n;c[m]= 1;} } ll poww(ll a, ll b) {ll ans= 1;while (b) {if (b & 1)ans= ans * a % mod;a= a * a % mod;b>>= 1;}return ans; } int main() {//rd_test();cin >> a >> b;divide(a);for (int i= 1; i <= m; i++) {if ((p[i] - 1) % mod == 0) {ans= ((1ll * b * c[i] + 1) % mod) * ans % mod;continue;}int x= poww(p[i], 1ll * b * c[i] + 1); //分子x= (x - 1 + mod) % mod;int y= p[i] - 1; //分母y= poww(y, mod - 2);ans= 1ll * ans * x % mod * y % mod;}cout << ans << endl;//Time_test(); }

總結

以上是生活随笔為你收集整理的Sumdiv POJ - 1845的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。