Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined), problem: (E) Bash Plays with Functions Solution in C/C++

#include <cstdio>
const int mod = 1000000007;
int a[1000010][21];
int b[1000010];
int main() {
	int q, r, n;
	a[0][0] = 1;
	for (int j = 1; j < 21; j++) {
		a[0][j] = 2;
	}
	for (int i = 1; i < 1000010; i++) {
		a[i][0] = 1;
		for (int j = 1; j < 21; j++) {
			a[i][j] = a[i-1][j] + a[i][j-1];
			if (a[i][j] >= mod) {
				a[i][j] -= mod;
			}
		}
	}
	for (int i = 2; i < 1000010; i++) {
		if (b[i]) continue;
		for (int j = i; j < 1000010; j += i) {
			b[j] = i;
		}
	}
	scanf("%d", &q);
	while (q--) {
		scanf("%d%d", &r, &n);
		int ans = 1;
		while (n != 1) {
			int k = b[n];
			int c = 0;
			while (n % k == 0) {
				n /= k;
				++c;
			}
			ans = (long long)ans * a[r][c] % mod;
		}
		printf("%d\n", ans);
	}
	return 0;
}
#include <cstdio>
const int mod = 1000000007;
int a[1000010][21];
int b[1000010];
int main() {
	int q, r, n;
	a[0][0] = 1;
	for (int j = 1; j < 21; j++) {
		a[0][j] = 2;
	}
	for (int i = 1; i < 1000010; i++) {
		a[i][0] = 1;
		for (int j = 1; j < 21; j++) {
			a[i][j] = a[i-1][j] + a[i][j-1];
			if (a[i][j] >= mod) {
				a[i][j] -= mod;
			}
		}
	}
	for (int i = 2; i < 1000010; i++) {
		if (b[i]) continue;
		for (int j = i; j < 1000010; j += i) {
			b[j] = i;
		}
	}
	scanf("%d", &q);
	while (q--) {
		scanf("%d%d", &r, &n);
		int ans = 1;
		while (n != 1) {
			int k = b[n];
			int c = 0;
			while (n % k == 0) {
				n /= k;
				++c;
			}
			ans = (long long)ans * a[r][c] % mod;
		}
		printf("%d\n", ans);
	}
	return 0;
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

I Tried Viral Kitchen Gadgets For 30 Days Here Is the Honest Truth

📢 As an Amazon Associate, I earn from qualifying purchases.Most products in this category disappoint within weeks. Cheap materials, vague instructions, and results that...

Amala meal: Kogi probes deaths of four family members

The Kogi State Government has officially commenced an exhaustive investigation following the tragic demise of four family members in Ihima, located within the Okehi...

I Tried Viral Kitchen Gadgets For 30 Days Here Is the Honest Truth

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!