改错
:::warning[5]{open}
1.题目大意:
计算
2.思路:
递推:
令
由画图可知,用上半部分加下半部分加合并部分即可,
ps:注意中间部分不是从
3.代码:
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N = 1e5 + 50;
ull n;
ull f[N], g[N];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// freopen("rec.in", "r", stdin);
// freopen("rec.out", "w", stdout);
cin >> n;
f[1] = (n * n - n) / 2 + n;
g[1] = n;
for (ull i = 2; i <= n; ++i) {
f[i] = f[1] + f[i - 1] + f[1] * (i - 1);
g[i] = g[i - 1] + g[1] + n * (i - 1) - (i * i - i) / 2;
}
cout << f[n] - g[n];
return 0;
}
| ps:好像要开__int128。 |
|---|
| :::info[第 1 题: square 平方数 |
| ### 1.题目大意: |
| 求一个数的最大的平方约数。 |
| ### 2.思路: |
| 枚举平方数。 |
| ### 3.代码: |
| ```cpp |
| #include<bits/stdc++.h> |
| using namespace std; |
| typedef long long ll; |
| ll n; |
| int main() { |
| ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); |
| // freopen("square.in", "r", stdin); |
| // freopen("square.out", "w", stdout); |
| cin >> n; |
| for (ll i = (ll)sqrt(n); i >= 1; --i) { |
| if (n % (i * i) == 0) { |
| cout << i * i; |
| return 0; |
| } |
| } |
| return 0; |
| } |
| ``` |
:::
:::warning[2]
1.题目大意:
从
2.思路:
求
3.代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
ll n, m, res = 1;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// freopen("lineup.in", "r", stdin);
// freopen("lineup.out", "w", stdout);
cin >> n >> m;
for (ll i = n; i >= n - m + 1; --i) {
(res *= (i % MOD)) %= MOD;
}
cout << res;
return 0;
}
ps: 错因:
未对
:::success[3]
1.题目大意:
求第
(优美数指含有
2.思路:
打表(离线)。
3.代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 50;
ll t, k[N], cnt, ans, n;
ll a[N];
bool check(ll x) {
if (x % 7 == 0) return 1;
while (x) {
if (x % 10 == 7) return 1;
x /= 10;
}
return 0;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// freopen("beauty.in", "r", stdin);
// freopen("beauty.out", "w", stdout);
cin >> t;
for (int i = 1; i <= t; ++i) cin >> k[i], n = max(n, k[i]);
for (int i = 1; cnt < n; ++i) {
if (check(i)) {
a[++cnt] = i;
}
}
for (int i = 1; i <= t; ++i) {
cout << a[k[i]] << "\n";
}
return 0;
}
:::
:::info[第 4 题: hundred 倍数
1.题目大意:
在数组
2.思路:
将
3.代码:
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N = 150;
ull n, a[N];
ull ans;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// freopen("hundred.in", "r", stdin);
// freopen("hundred.out", "w", stdout);
cin >> n;
for (int i = 1; i <= n; ++i) {
int cn;
cin >> cn;
a[cn % 100]++;
}
for (int i = 0; i < 100; ++i) {
if (a[i] > 1) {
ans += a[i] * (a[i] - 1) / 2;
}
}
cout << ans;
return 0;
}
ps错因:
未使用桶记录。
:::
:::error[6]
1.题目大意:
求阶乘的约数个数。
2.思路:
唯一分解后将所有指数加
3.代码:
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N = 1e5 + 50;
int n;
int a[150];
ull ans = 1;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int man = 2; man <= n; ++man) {
int qq = man;
for (int i = 2; i <= qq / i; ++i) {
if (qq % i == 0) {
while (qq % i == 0) {
a[i]++;
qq /= i;
}
}
}
if (qq > 1) {
a[qq]++;
}
}
for (int i = 1; i <= 100; ++i) {
ans *= (a[i] + 1);
}
cout << ans;
return 0;
}
:::