# 官方题解|欢乐赛#40
2025-02-11 16:26:35
发布于:浙江
官方题解|欢乐赛#40
T1
2025下一个闰年是2028年,所以答案是2028。
#include <bits/stdc++.h>
using namespace std;
int main(){
cout << "2028";
return 0;
}
T2
我们只需要考虑个位即可,, ,以此类推,可以发现只要是奇数次方,结果就是 ,偶数次方,结果就是 。
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int a[N], n, m, k;
void solve(){
cin >> n;
if(n & 1) cout << 4 << endl;
else cout << 6 << endl;
}
signed main(){
int tt = 1;
cin >> tt;
while(tt -- ){
solve();
}
return 0;
}
T3
本题只要利用for循环直接模拟即可,但是注意要开long long,另外要不断的取模哦。
#include <bits/stdc++.h>
using namespace std;
const int N = 200010, mod = 998244353;
int a[N], n, m, k;
int main(){
cin >> n;
long long ans = 1;
for(int i = 1; i <= n; i ++ ){
ans = ans * 114514 % mod;
}
cout << ans;
return 0;
}
T4
本题只要从1开始的枚举所有的数,利用 代表当前有多少质数,只要是质数,就加一,直到 等于 。
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int a[N], n, m, k;
bool is_prime(int x){
for(int i = 2; i * i <= x; i ++ ){
if(x % i == 0) return false;
}
return true;
}
int main(){
int n; cin >> n;
int now = 0, idx = 2;
while(now < n){
if(is_prime(idx)) now ++;
idx ++;
}
cout << idx - 1 << endl;
return 0;
}
T5
这题可以举几个例子思考下,比如原数组为,就是 个人的座位号都和自己的学号一样的话,那么至少需要交换次。如果有偶数个人的座位号都和自己的学号一样,那么只要两个两个交换即可,所以当不合法的数量是奇数,答案是,否则答案是 。
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int a[N], n, m, k;
void solve(){
cin >> n;
for(int i = 1; i <= n; i ++ ) cin >> a[i];
int ans = 0;
for(int i = 1; i <= n; i ++ ){
ans += a[i] == i;
}
cout << (ans + 1) / 2 << endl;
}
int main(){
int tt = 1;
cin >> tt;
while(tt -- ){
solve();
}
return 0;
}
T6
本题是个诈骗题,其实最长因子区间一定从 开始。因为对于任意的数,都能在区间中找到 个因子。所以只要求起点是 的区间即可。
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 200010;
int a[N], n, m, k;
void solve(){
vector<int>factors;
int n; cin >> n;
int cnt = 0;
for(int i = 1; i <= n; i ++ ){
if(n % i == 0) cnt ++;
else break;
}
cout << cnt << endl;
}
signed main(){
int tt = 1;
cin >> tt;
while(tt -- ){
solve();
}
return 0;
}
这里空空如也
有帮助,赞一个