HDU5525 乘法原理

2021-07-06 07:59:27 字數 1237 閱讀 1720

首先把每乙個數拆成質因數的乘積,把對應的次數累計起來。然後設第i個質因數的指數累計的和是ai,那麼i^t(0<=t<=ai)這個因子出現的次數就是(1+a1)*(1+a2)*...*(1+ak)/(1+ai)。

然後各種取模。

#include #include #include #include #include using namespace std;

#define maxn 111111

long long mod = 1e9+7;

long long num[maxn], a[maxn];

vector fac[maxn];

long long pre[maxn], last[maxn]; //字首乘積,字尾乘積

bool is_prime[maxn];

long long prime[maxn], cnt;

long long n;

long long kk;

long long qpow (long long a, long long b)

return ans%mod;

}long long get (long long cur, int pos, int tot)

else ans = (num[cur]/2)%mod2*((num[cur]+1)%mod2) % mod2;

if (tot == 1)

else if (pos == 0)

else if (pos == tot-1)

else ans = ans*pre[pos-1]%mod2*last[pos+1]%mod2;

return ans;

}void solve ()

for (int i = 0; i < tot; i++)

for (int i = tot-1; i >= 0; i--)

for (int i = 0; i < tot; i++)

printf ("%lld\n", ans);

}int main () }}

for (int i = 1; i <= 100000; i++)

for (int i = 1; i <= 100000; i++)

}while (scanf ("%lld", &n) == 1)

num[cur] += tot;}}

solve ();

}return 0;

}

加法原理和乘法原理

設事件a有m種產生方式,事件b有n種產生方式,則當a和b的產生方式不重疊時,事件a或b之一 有m n種產生方式。可推廣多個事件 設事件a有m種產生方式,事件b有n種產生方式,則當a和b的產生方式彼此獨立時,事件a與b有m n種產生方式。無論事件a採用何種方式產生,都不影響事件b。可推廣多個事件 例1...

hdu4920(矩陣 乘法)

題意 矩陣乘法,在乘的過程中每個元素都取模3 在比賽時,我一直在想怎麼才能把o n n n 的時間複雜度給降下來,可是一直沒想到好的辦法,後來看了題解後才知道原來時間複雜度還是o n n n 只是優化了一點而已 如下 include include include include include i...

HDU4920 矩陣乘法

嗯嗯 就算是水題吧。縮完行就15行 題意 兩個n n的矩陣相乘 n 800 結果對3取模 思路 先對3取模,所以兩個矩陣裡面會出現很多0,所以可以先列舉乙個矩陣,只有當該位置不是0的時候才和另乙個矩陣做乘法。取模的時候也有技巧,不要在計算的途中取模,應該讀入的時候取一次模,輸出的時候取一次模 計算量...