杂题练习10.10

版权声明:博主是菜鸡,但转的时候还是说一声吧 https://blog.csdn.net/qq_37666409/article/details/83187126

高三狗还要考noip实在是太惨了,班主任不给停课,只有晚自习溜到机房练练题,整理一下

每天在vj上拉个比赛自己打……想着都心酸

Atcoder4257

长度为n的正整数构成的数列{an}积为m,求这样的数列有多少个,答案mod1000000007

将m分解,对于m的一个质因子p,假设其次数为b,因为任意ai必然是m的因子,所以ai中p的次数必然小于等于b且大于等于0

就相当于是将b个p划分为n个集合,允许为空

就是一个隔板法

取模取少了调了30min……

#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;
 
const int MAXN = 500500;
const int MAXE = 400400;
const int INF = 0x3f3f3f3f;
 
template<typename T> inline void CheckMax(T &A, T B) {
	A < B ? A = B : A;
}
 
template<typename T> inline void CheckMin(T &A, T B) {
	A > B ? A = B : A;
}
 
template <typename T> inline void read(T &x) {
    int c = getchar();
    bool f = false;
    for (x = 0; !isdigit(c); c = getchar()) {
        if (c == '-') {
            f = true;
        }
    }
    for (; isdigit(c); c = getchar()) {
        x = x * 10 + c - '0';
    }
    if (f) {
        x = -x;
    }
}
 
LL n, m;
LL P[MAXN], cnt;

const LL mod = 1000000007;

LL qpow(LL a, LL b) {
	LL ret = 1;
	while(b) {
		if(b & 1) ret *= a;
		ret %= mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ret;
}

#define inv(x) qpow(x, mod - 2)
LL fac[MAXN + 10];

void init() {
	fac[0] = 1;
	for(LL i = 1; i <= MAXN; i++) fac[i] = fac[i - 1] * i % mod;
}

LL C(LL a, LL b) {
    return (fac[a] * inv(fac[b]) % mod * inv(fac[a - b]) % mod);
}

void solve(LL x) {
	for(LL i = 2; i * i <= x; i++) {
		if(x % i == 0) {
			LL cur = 0;
			while(x % i == 0) {
				x /= i;
				cur++;
			}
			P[++cnt] = cur;
		}
	}
	if(x > 1) P[++cnt] = 1;
}
 
signed main() {
	cin >> n >> m;
	solve(m);
	LL ans = 1LL;
	init();
	for(LL i = 1; i <= cnt; i++) {
		ans *= (LL) C(P[i] + n - 1LL, n - 1LL) % mod;
		ans %= mod;
	}
	printf("%lld\n", ans);
	return 0;
}

atcoder4244

将区间转化到一个二维数组上,就是一道思博题了

#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;

template <typename T> inline void read(T &x) {
    int c = getchar();
    bool fg = false;
    for (x = 0; !isdigit(c); c = getchar()) {
        if (c == '-') {
            fg = true;
        }
    }
    for (; isdigit(c); c = getchar()) {
        x = x * 10 + c - '0';
    }
    if (fg) {
        x = -x;
    }
}
const int MAXN = 550;
const int INF = 0x3f3f3f3f;

int f[MAXN][MAXN], n, m, q;

signed main() {
	read(n), read(m), read(q);
	for(int i = 1; i <= m; i++) {
		int l, r;
		read(l), read(r);
		f[l][r]++;
		f[r][l]++;
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			f[i][j] = f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1] + f[i][j];
		}
	}
	while(q--) {
		int l, r;
		read(l), read(r);
		int ans = f[r][r] - f[r][l - 1] - f[l - 1][r] + f[l - 1][l - 1];
		printf("%d\n", ans >> 1);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37666409/article/details/83187126