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

US suspends green-card filings by Cognizant amid visa-fraud probe: ‘Threats to American workers…’

In a major regulatory development impacting the global tech sector, the United States Department of Labor has halted green-card processing applications for IT services...

7 Reasons This Viral Kitchen Gadgets Is Worth Every Single Penny

📢 As an Amazon Associate, I earn from qualifying purchases.After putting the Viral Kitchen Gadgets through a proper 30-day real-world test, I can tell...

How long should I bleach my live rock?

When resetting an aquarium or dealing with persistent pests like bubble algae, aiptasia, and unwanted parasites, bleaching live rock is often the most reliable...

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!