hdu-2421 Deciphering Password 数学姿势
生活随笔
收集整理的這篇文章主要介紹了
hdu-2421 Deciphering Password 数学姿势
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
給定A,B,對于A^B的每一個因子,M為其因子的因子數的三次方求和。
容易推導得出A^B的每一個因子都是A的質因子的組合(質因子可重復利用),其因子數自然等于所使用的每個質因子的數量乘積。
假設A由質因子a1,a2,a3組合而成,對應數量為k1,k2,k3,那么A的因子數為(k1+1)*(k2+1)*(k3+1),同理A的因子的因子數為(k1+1)*(k2+1)*k3+1,(k1+1)*k2*(k3+1),k1*(k2+1)*(k3+1),(k1+1)*k2*k3以此類推。
我們可以發現其為(1+2+3...k1+1)*(1+2+3...k2+1)*(1+2+3...k3+1)的展開。對于這里的每一項,我們可以用求和公式(n*(n+1)/2)^2來求解。
對于拆解一個數的質因數,我們只需要枚舉到srqt(n)即可,因為至多只有一個質因數大于sqrt(n) n不斷做除法剩下的數即是這個質因數,如果有兩個質因數x1,x2大于sqrt(n),那一定有n>=x1*x2與x1>sqrt(n) x2>sqrt(n)相悖。
#include <iostream> #include <cstring> #include <string> #include <queue> #include <vector> #include <map> #include <set> #include <stack> #include <cmath> #include <cstdio> #include <algorithm> #define LL long long using namespace std; const LL N = 1000005; const LL mod = 10007; LL cube(LL num) {return (num*(num + 1) / 2)%mod*(num*(num + 1) / 2); } vector<LL> su; bool vis[N]; int main() {//cin.sync_with_stdio(false); LL a,b;fill(vis, vis + N, true);vis[0] = vis[1] = false;for(LL i=2;i<N;i++)if (vis[i]){su.push_back(i);for (LL j = i * 2; j < N; j *= i)vis[i] = false;}int cas = 1;while (scanf("%lld%lld",&a,&b)!=EOF){map<LL, LL> mp;for (LL i = 0; i < su.size() && su[i]*su[i] <= a; i++){while (a%su[i] == 0)cout << su[i] << endl, mp[su[i]]++, a /= su[i];}if (a > 1)mp[a]++;LL ans = 1;for (map<LL, LL>::iterator it = mp.begin(); it != mp.end(); it++){it->second *= b, it->second++;it->second %= mod;//cout << it->second << endl;ans *= cube(it->second);ans %= mod;}printf("Case %d: %lld\n", cas++, ans);//cout << "Case " << cas++<<": ";//cout << ans << endl; }return 0; }?
轉載于:https://www.cnblogs.com/LukeStepByStep/p/7452281.html
總結
以上是生活随笔為你收集整理的hdu-2421 Deciphering Password 数学姿势的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 滴滴笔试
- 下一篇: Eclipse的PyDev插件安装及解决