一個很大的數(計數、思維)
阿新 • • 發佈:2022-03-31
題意
我有一個數\(x\),但這裡空白太小寫不下,將\(x\)表示為
\(x=\prod_{i=1}^{n}p_i^{c_i}\)
其中\(p_i\)為素數且互不相同
\(T\)組測試用例,輸出\(x\)的因子有多少對互質
資料範圍
\(n \leq 1e4\)
\(1 \leq p_i, c_i \leq 1e9\)
\(T\leq 100\)
思路
對於一個互質的因子對\((a,b)\)
每種因子只能分配給\(a\)或分配給\(b\),或者均不分配
故每種因子有\(2c_i+1\)種分配方案:\((0, 0), (1, 0)\dots (c_i,0), (0,1)\dots (0, c_i)\)
\(ans = \prod_{i=1}^{n}(2c_i + 1)\)
程式碼
#include <iostream> #include <cstdio> using namespace std; typedef long long ll; const int mod = 1e9 + 7; int main() { int T; scanf("%d", &T); while(T --) { ll ans = 1; int n; scanf("%d", &n); for(int i = 1; i <= n; i ++) { ll p, c; scanf("%lld%lld", &p, &c); ans = (ans * (2 * c + 1)) % mod; } printf("%lld\n", ans); } return 0; }