[COCI2020-2021#4] Vepar
[COCI2020-2021#4] Vepar
题意
给定两组正整数
思路
将
将
题意转化为
使用阶乘分解这道题的做法把分子分母分别分解质因数,判断即可。
以下是阶乘分解的做法:
考虑质数
答案为
因为
而
其它同理。
时间复杂度:
代码
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int N = 1e7 + 5;
int pr[N], cnt, id[N];
bool is[N];
void pri() {
for (int i = 2; i <= 1e7; i ++) {
if (!is[i]) pr[++ cnt] = i, id[i] = cnt;
for (int j = 1; j <= cnt && i * pr[j] <= 1e7; j ++) {
is[i * pr[j]] = 1;
if (i % pr[j] == 0) break;
}
}
}
void get(int n, int* c, int v) {
ll k, ans;
for(int i=1;i<=cnt;i++)
{
k=pr[i];
ans=0;
while(k<=n) {
ans+=(n/k);
k *= pr[i];
}
c[i] += ans * v;
}
}
int c1[N], c2[N];
void solve() {
int a, b, c, d;
cin >> c >> d >> a >> b;
get(d, c1, 1); get(a - 1, c1, 1);
get(c - 1, c2, 1); get(b, c2, 1);
bool ok = 1;
for (int i = 1; i <= cnt; i ++)
if (c2[i] < c1[i]) ok = 0;
if (ok) cout << "DA\n";
else cout << "NE\n";
memset(c1, 0, sizeof(c1));
memset(c2, 0, sizeof(c2));
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
pri();
int T = 1;
cin >> T;
while (T --)
solve();
return 0;
}
本文来自博客园,作者:maniubi,转载请注明原文链接:https://www.cnblogs.com/maniubi/p/18407223,orz
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】