A - Find Multiple
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
int a, b, c;
cin >> a >> b >> c;
for (int i = a; i <= b;i++){
if(i%c==0){
cout << i;
return 0;
}
}
cout << -1;
return 0;
}
B - Base K
一开始没开long long WA了一发,我傻逼
#include<bits/stdc++.h>
using namespace std;
int k;
long long f(string s){
long long num = 0, m = 1;
for (int i = s.size() - 1; i >= 0;i--){
num += (s[i] - '0') * m;
m *= k;
}
return num;
}
int main(){
ios::sync_with_stdio(0);
cin >> k;
string a, b;
cin >> a >> b;
cout << f(a) * f(b);
return 0;
}
C - Long Sequence
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
long long n, x, sum=0;
long long a[100100];
cin >> n;
for (int i = 0; i < n; i++){
cin >> a[i];
sum += a[i];
}
//cout << sum;//10
cin >> x;
long long m;
m = x / sum;
x = x - sum * m;
long long num=0,cnt=0;
for (int i = 0; i < n;i++){
if(num>x){
break;
}
num += a[i];
cnt++;
}
cout << n * m + cnt;
return 0;
}
D - FG operation
dp数组开大必TLE
#include<bits/stdc++.h>
using namespace std;
#define mod 998244353
int main(){
ios::sync_with_stdio(0);
int n;
int a[100100],dp[100010][12];
for (int i = 1; i <= n;i++){
cin >> a[i];
}
dp[1][a[1]] = 1;
for (int i = 1; i <= n;i++){
for (int j = 0; j < 10;j++){
if(dp[i][j]){
dp[i + 1][(j + a[i + 1]) % 10] += dp[i][j];
dp[i + 1][(j + a[i + 1]) % 10] %= mod;
dp[i + 1][(j * a[i + 1]) % 10] += dp[i][j];
dp[i + 1][(j * a[i + 1]) % 10] %= mod;
}
}
}
for (int i = 0; i < 10 ;i++)
cout << dp[n][i] << "\n";
return 0;
}