Skip to content

Commit

Permalink
contest 1968 div 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanashii76 authored May 2, 2024
1 parent b623fb9 commit e0455fc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Codeforces/contest1968/A.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <bits/stdc++.h>
using namespace std;

int gcd(int a, int b)
{
int result = min(a, b);
while (result > 0) {
if (a % result == 0 and b % result == 0) {
break;
}
result--;
}

return result;
}


int main(){

int n; cin >> n;
while(n--) {
int t; cin >> t;
int maxGcd = 0, idx = 0;
for(int i = 1; i < t; ++i) {
if( gcd(t,i)+i > maxGcd ) {
idx = i;
maxGcd = gcd(t,i)+i;
}
}
cout << idx << endl;
}

return 0;
}
22 changes: 22 additions & 0 deletions Codeforces/contest1968/B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <bits/stdc++.h>
using namespace std;

int main(){

int n; cin >> n;
while(n--) {
int a,b; cin >> a >> b;
string a1, a2; cin >> a1 >> a2;

int ans = 0;

for(int i = 0, j = 0; i < (int)a2.length(); ++i) {
if(a2[i] == a1[j]) {
ans++;
j++;
}
}

cout << ans << endl;
}
}

0 comments on commit e0455fc

Please sign in to comment.