0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-08 14:18:47 +00:00

Compare commits

...

4 Commits

4 changed files with 163 additions and 0 deletions

42
Luogu/B3871/B3871.cpp Normal file
View File

@ -0,0 +1,42 @@
#include <iostream>
#include <cmath>
using std::cin;
using std::cout;
const char endl = '\n';
long long n;
bool flag;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
long long x = n;
for (long long i = 2; i <= std::sqrt(n); i++) {
if (x % i == 0) {
int cnt = 0;
while (x % i == 0) x /= i, cnt++;
if (flag) cout << " * ";
else flag = true;
if (cnt > 1) {
cout << i << '^' << cnt;
} else {
cout << i;
}
}
}
if (x > 1) {
if (flag) cout << " * ";
cout << x;
}
return 0;
}

48
Luogu/B3872/B3872.cpp Normal file
View File

@ -0,0 +1,48 @@
#include <iostream>
#include <algorithm>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 505;
int n, ans;
bool t[N];
struct node {
int t, r;
} a[N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].t;
}
for (int i = 1; i <= n; i++) {
cin >> a[i].r;
}
std::sort(a + 1, a + 1 + n, [&](const node &a, const node &b) {
return a.r > b.r;
});
for (int i = 1; i <= n; i++) {
for (int j = a[i].t; j; j--) {
if (!t[j]) {
t[j] = true;
ans += a[i].r;
break;
}
}
}
cout << ans << endl;
return 0;
}

39
Luogu/B3941/B3941.cpp Normal file
View File

@ -0,0 +1,39 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 15;
int n, a[N], ans;
int gcd(int x, int y) {
if (x == 0) return y;
return gcd(y % x, x);
}
int lcm(int x, int y) {
return x / gcd(x, y) * y;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
ans = a[0];
for (int i = 1; i < n; i++) {
ans = lcm(ans, a[i]);
}
cout << ans << endl;
return 0;
}

34
Luogu/B3969/B3969.cpp Normal file
View File

@ -0,0 +1,34 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e6 + 5;
int n, b, a[N]{0, 1}, cnt;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> b;
for (int i = 2; i <= n; i++) {
if (a[i] == 0) {
for (int j = i; j <= n; j += i) {
a[j] = i;
}
}
}
for (int i = 1; i <= n; i++) {
if (a[i] <= b) {
cnt++;
}
}
cout << cnt << endl;
return 0;
}