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

Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.
#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;
}

📦 Looking for Codecraft 17 Codeforces Round 391 Div? Check the best deals on Amazon.

🛒 Shop Codecraft 17 Codeforces Round 391 Div on Amazon

As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.

Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.
#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;
}

📦 Looking for Codecraft 17 Codeforces Round 391 Div? Check the best deals on Amazon.

🛒 Shop Codecraft 17 Codeforces Round 391 Div on Amazon

As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Where Is the Outrage? Profound Autism Didn’t Used to Exist — Now It’s Everywhere

Decades ago, the landscape of primary education looked radically different than it does today. In the late 1970s, typical elementary school environments rarely featured...

How Viral Kitchen Gadgets Is Quietly Changing the Game

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

How Viral Kitchen Gadgets Is Quietly Changing the Game

📢 As an Amazon Associate, I earn from qualifying purchases.I stumbled across this while desperately trying to fix a recurring problem in my routine....

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!