Submission #56609081


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define pb push_back

using ll = long long;

const int MOD = 998244353, primes[] = {2, 3, 5, 7, 11, 13};
ll N;
int M, cnt[25][6], s[(1 << 6) + 1];

struct matrix {
    int mat[(1 << 6) + 1][(1 << 6) + 1];
    matrix friend operator *(const matrix &a, const matrix &b){
        matrix c;
        for (int i = 0; i <= (1 << 6); i++) {
          for (int j = 0; j <= (1 << 6); j++) {
              c.mat[i][j] = 0;
              for (int k = 0; k <= (1 << 6); k++) {
                  c.mat[i][j] += (ll)a.mat[i][k] * b.mat[k][j] % MOD;
                  if (c.mat[i][j] >= MOD) {
					  c.mat[i][j] -= MOD;
				  }
              }
          }
        }
        return c;
    }
};

matrix matpow(matrix base, ll n) {
    matrix ans;
    for (int i = 0; i <= (1 << 6); i++) {
		for (int j = 0; j <= (1 << 6); j++) {
			ans.mat[i][j] = (i == j);
		}
	}
    while (n) {
        if (n % 2 == 1) {
            ans = ans * base;
		}
        base = base * base;
        n /= 2;
    }
    return ans;
}

matrix base;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		int cur = i;
		for (int j = 0; j < 6; j++) {
			while (cur % primes[j] == 0) {
				cnt[i][j]++;
				cur /= primes[j];
			}
		}
	}
	for (int i = 0; i <= (1 << 6); i++) {
		for (int j = 0; j <= (1 << 6); j++) {
			base.mat[i][j] = 0;
		}
	}
	for (int bm = 0; bm < (1 << 6); bm++) {
		for (int i = 1; i <= M; i++) {
			vector<int> poss;
			for (int j = 0; j < 6; j++) {
				if (!(bm & (1 << j)) && cnt[i][j]) {
					poss.pb(j);
				}
			}
			for (int j = 0; j < (1 << (int)poss.size()); j++) {
				int new_bm = bm, mul = 1;
				for (int k = 0; k < (int)poss.size(); k++) {
					if (j & (1 << k)) {
						new_bm |= (1 << poss[k]);
						mul = (ll)mul * cnt[i][poss[k]] % MOD;
					}
				}
				base.mat[bm][new_bm] += mul;
				if (base.mat[bm][new_bm] >= MOD) {
					base.mat[bm][new_bm] -= MOD;
				}
			}
		}
		base.mat[bm][1 << 6] = 1;
	}
	base.mat[1 << 6][1 << 6] = 1;
	auto res = matpow(base, N - 1);
	for (int i = 0; i <= (1 << 6); i++) {
		for (int j = 0; j <= (1 << 6); j++) {
			s[i] += res.mat[i][j];
			if (s[i] >= MOD) {
				s[i] -= MOD;
			}
		}
	}
	int ret = 0, bm = 0;
	for (int i = 1; i <= M; i++) {
		vector<int> poss;
		for (int j = 0; j < 6; j++) {
			if (!(bm & (1 << j)) && cnt[i][j]) {
				poss.pb(j);
			}
		}
		for (int j = 0; j < (1 << (int)poss.size()); j++) {
			int new_bm = bm, mul = 1;
			for (int k = 0; k < (int)poss.size(); k++) {
				if (j & (1 << k)) {
					new_bm |= (1 << poss[k]);
					mul = (ll)mul * cnt[i][poss[k]] % MOD;
				}
			}
			ret += (ll)s[new_bm] * mul % MOD;
			if (ret >= MOD) {
				ret -= MOD;
			}
		}
	}
	cout << ret << '\n';
}

Submission Info

Submission Time
Task C - Sum of Number of Divisors of Product
User pavement
Language C++ 20 (gcc 12.2)
Score 600
Code Size 2860 Byte
Status AC
Exec Time 57 ms
Memory 3660 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 51
Set Name Test Cases
Sample 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt
All 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 01-random-001.txt, 01-random-002.txt, 01-random-003.txt, 01-random-004.txt, 01-random-005.txt, 01-random-006.txt, 01-random-007.txt, 01-random-008.txt, 01-random-009.txt, 01-random-010.txt, 02-large-001.txt, 02-large-002.txt, 02-large-003.txt, 02-large-004.txt, 02-large-005.txt, 02-large-006.txt, 02-large-007.txt, 02-large-008.txt, 02-large-009.txt, 02-large-010.txt, 03-max-001.txt, 03-max-002.txt, 03-max-003.txt, 03-max-004.txt, 03-max-005.txt, 04-small-001.txt, 04-small-002.txt, 04-small-003.txt, 04-small-004.txt, 04-small-005.txt, 04-small-006.txt, 04-small-007.txt, 04-small-008.txt, 04-small-009.txt, 04-small-010.txt, 05-killer-001.txt, 05-killer-002.txt, 05-killer-003.txt, 06-corner-001.txt, 06-corner-002.txt, 06-corner-003.txt, 06-corner-004.txt, 06-corner-005.txt, 06-corner-006.txt, 06-corner-007.txt, 06-corner-008.txt, 06-corner-009.txt, 06-corner-010.txt
Case Name Status Exec Time Memory
00-sample-001.txt AC 1 ms 3452 KiB
00-sample-002.txt AC 2 ms 3548 KiB
00-sample-003.txt AC 13 ms 3472 KiB
01-random-001.txt AC 42 ms 3520 KiB
01-random-002.txt AC 43 ms 3472 KiB
01-random-003.txt AC 44 ms 3500 KiB
01-random-004.txt AC 38 ms 3520 KiB
01-random-005.txt AC 41 ms 3500 KiB
01-random-006.txt AC 47 ms 3476 KiB
01-random-007.txt AC 41 ms 3476 KiB
01-random-008.txt AC 44 ms 3472 KiB
01-random-009.txt AC 42 ms 3660 KiB
01-random-010.txt AC 43 ms 3580 KiB
02-large-001.txt AC 41 ms 3544 KiB
02-large-002.txt AC 42 ms 3580 KiB
02-large-003.txt AC 44 ms 3452 KiB
02-large-004.txt AC 44 ms 3456 KiB
02-large-005.txt AC 40 ms 3524 KiB
02-large-006.txt AC 43 ms 3384 KiB
02-large-007.txt AC 43 ms 3504 KiB
02-large-008.txt AC 41 ms 3528 KiB
02-large-009.txt AC 43 ms 3528 KiB
02-large-010.txt AC 38 ms 3388 KiB
03-max-001.txt AC 49 ms 3500 KiB
03-max-002.txt AC 48 ms 3480 KiB
03-max-003.txt AC 48 ms 3528 KiB
03-max-004.txt AC 48 ms 3536 KiB
03-max-005.txt AC 48 ms 3456 KiB
04-small-001.txt AC 1 ms 3532 KiB
04-small-002.txt AC 2 ms 3516 KiB
04-small-003.txt AC 2 ms 3476 KiB
04-small-004.txt AC 3 ms 3528 KiB
04-small-005.txt AC 3 ms 3580 KiB
04-small-006.txt AC 4 ms 3536 KiB
04-small-007.txt AC 3 ms 3548 KiB
04-small-008.txt AC 4 ms 3500 KiB
04-small-009.txt AC 3 ms 3472 KiB
04-small-010.txt AC 4 ms 3532 KiB
05-killer-001.txt AC 54 ms 3388 KiB
05-killer-002.txt AC 55 ms 3472 KiB
05-killer-003.txt AC 57 ms 3472 KiB
06-corner-001.txt AC 1 ms 3528 KiB
06-corner-002.txt AC 1 ms 3512 KiB
06-corner-003.txt AC 2 ms 3592 KiB
06-corner-004.txt AC 2 ms 3532 KiB
06-corner-005.txt AC 3 ms 3472 KiB
06-corner-006.txt AC 2 ms 3500 KiB
06-corner-007.txt AC 3 ms 3584 KiB
06-corner-008.txt AC 3 ms 3388 KiB
06-corner-009.txt AC 3 ms 3584 KiB
06-corner-010.txt AC 3 ms 3532 KiB