A.
得开ll
// Problem: A. Road To Zero
// Contest: Codeforces - Educational Codeforces Round 86 (Rated for Div. 2)
// URL: https://codeforces.com/group/RAx5fiilkP/contest/1342/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N];
void Lan(){
ll x,y;
cin>>x>>y;
ll a,b;
cin>>a>>b;
if(a+a>b){
cout<<min(x,y)*b+abs(x-y)*a<<'\n';
}else{
cout<<(x+y)*a<<'\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while (q--) {
Lan();
}
return 0;
}
B.
周期要么是1要么是2
// Problem: B. Binary Period
// Contest: Codeforces - Educational Codeforces Round 86 (Rated for Div. 2)
// URL: https://codeforces.com/group/RAx5fiilkP/contest/1342/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N];
void Lan(){
string t;
cin>>t;
int n=t.length();
int cnt0=0;
for(int i=0;i<n;i++){
if(t[i]=='0'){
cnt0++;
}
}
int cnt1=n-cnt0;
if(cnt0 && cnt1){
if(t[0]=='0'){
for(int i=1;i<=2*n;i++){
if(i&1){
cout<<0;
}else{
cout<<1;
}
}
cout<<'\n';
return;
}else{
for(int i=1;i<=2*n;i++){
if(i&1){
cout<<1;
}else{
cout<<0;
}
}
cout<<'\n';
return;
}
}
if(cnt1 && !cnt0){
cout<<t<<'\n';
return;
}
if(!cnt1 && cnt0){
cout<<t<<'\n';
return;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while (q--) {
Lan();
}
return 0;
}
C.
建议打表找规律然后找到周期是lcm(a,b)
前缀和处理一个lcm(a,b)的范围
那就可以知道l在有几个数,r能有几个数,x不能到l-1,减去即可
// Problem: C. Yet Another Counting Problem
// Contest: Codeforces - Educational Codeforces Round 86 (Rated for Div. 2)
// URL: https://codeforces.com/group/RAx5fiilkP/contest/1342/problem/C
// Memory Limit: 256 MB
// Time Limit: 3500 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N=1e5+9;
ll prefix[N];
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll a,b,q;
ll work(ll x){
ll num=x/lcm(a,b);
ll ans=(num*prefix[lcm(a,b)])+prefix[x%lcm(a,b)];//num个周期+剩余数
return ans;
}
void Lan(){
cin>>a>>b>>q;
for(int i=1;i<=lcm(a,b);i++){
prefix[i]=prefix[i-1]+(i%a%b!=i%b%a);//计算一个周期
}
while(q--){
ll l,r;
cin>>l>>r;
cout<<work(r)-work(l-1)<<" ";//l-1 x到不了得减去
}
cout<<'\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t;
cin>>t;
while (t--) {
Lan();
}
return 0;
}