893E - Counting Arrays - CodeForces Solution


combinatorics dp math number theory *2000

Please click on ads to support us..

C++ Code:

#include <cstdio>
#include <cmath>
#include <algorithm>
#define ll long long
const int mod = 1000000007;
using namespace std;

int qkpow(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = (ll)res * x % mod;
		x = (ll)x * x % mod;
		y >>= 1;
	}
	return res;
}
struct mint{
	int x;
	mint() { x = 0; }
	mint(int _x) { x = _x % mod; }
	mint operator + (mint y) { return (x + y.x) % mod; }
	mint operator - (mint y) { return (x - y.x + mod) % mod; }
	mint operator * (mint y) { return (ll)x * y.x % mod; }
	mint operator / (mint y) { return (ll)x * qkpow(y.x, mod - 2) % mod; }
}; 

mint f[1000005], ans, sum;
mint C(int a, int b) {
	return f[a] / (f[b] * f[a - b]);
}

int q, n, m;

int main() {
	f[0] = 1;
	for (int i = 1; i <= (int)1e6; i++) {
		f[i] = f[i - 1] * i;
	}

	scanf("%d", &q);
	while (q--) {
		scanf("%d%d", &n, &m);
		int sq = (int)sqrt(n); 
		ans = 1;
		
		for (int i = 2, cnt; i <= sq; i++) {
			cnt = 0;
			while (n % i == 0) {
				n /= i;
				cnt ++;
			}
			if (!cnt) continue;
			
			sum = 0;
			for (int h = 1; h <= min(m, cnt); h++) {
				sum = sum + C(m, h) * C(cnt - 1, h - 1);
			}
			ans = ans * sum;
		}
		if (n > 1) ans = ans * m;
		
		ans = ans * qkpow(2, m - 1);
		printf("%d\n", ans.x);
	}
	return 0;
}
	  	 	 		  			 		 	  	  	  	


Comments

Submit
0 Comments
More Questions

2144. Minimum Cost of Buying Candies With Discount
Non empty subsets
1630A - And Matching
1630B - Range and Partition
1630C - Paint the Middle
1630D - Flipping Range
1328A - Divisibility Problem
339A - Helpful Maths
4A - Watermelon
476A - Dreamoon and Stairs
1409A - Yet Another Two Integers Problem
977A - Wrong Subtraction
263A - Beautiful Matrix
180C - Letter
151A - Soft Drinking
1352A - Sum of Round Numbers
281A - Word Capitalization
1646A - Square Counting
266A - Stones on the Table
61A - Ultra-Fast Mathematician
148A - Insomnia cure
1650A - Deletions of Two Adjacent Letters
1512A - Spy Detected
282A - Bit++
69A - Young Physicist
1651A - Playoff
734A - Anton and Danik
1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves