A-Masala
n=int(input())
k = list(map(int,input().split()))[:n]
a, b = 0, 0
for i in k:
s = max(a + i, b)
a = b
b = s
print(b)
B-masala
k,n=map(int,input().split())
if n%2==0:
print(0)
else:
print((n+1)//2+1)
p,k=map(int,input().split())
if (k + 3) % 2 == 0:
print((k + 3) // 2)
else:
print(0)
C-masala
C++ da
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
bool isPrime(int n) {
if (n <= 1) return false;
for (int i = 2; i <= sqrt(n); ++i) {
if (n % i == 0) return false;
}
return true;
}
int main() {
int n;
cin >> n;
vector<string> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int s = 0, h = 0;
for (int x = 2; x <= n; ++x) {
sort(a.begin(), a.end());
do {
int num = stoi(a[0]);
for (int i = 1; i < x; ++i) {
num = num * 10 + stoi(a[i]);
}
if (isPrime(num)) {
s = num;
break;
}
} while (next_permutation(a.begin(), a.end()));
if (s != 0) break;
}
for (int x = n; x > 1; --x) {
sort(a.begin(), a.end(), greater<string>());
do {
int num = stoi(a[0]);
for (int i = 1; i < x; ++i) {
num = num * 10 + stoi(a[i]);
}
if (isPrime(num)) {
h = num;
break;
}
} while (prev_permutation(a.begin(), a.end()));
if (h != 0) break;
}
if (h == 0 && s == 0) {
cout << 0 << endl;
} else {
if (s != h) cout << s << " " << h << endl;
else cout << s << endl;
}
return 0;
}
Yechim: |Moynaq IM| --> Isamatdin
Pythonda
import math
import random
from itertools import permutations, combinations
mod = int(1e9) + 7
def daraja(a, b, m=mod):
s=pow(a,b,m)
return s
def tub(n):
if n < 10:
return False
for i in range(100):
x = random.randint(1, 10**18) + 10
if x % n == 0:
x += 1
if daraja(x, n - 1, n) != 1:
return False
return True
def izla(digits):
min_prime = None
max_prime = None
checked_numbers = set()
for r in range(1, len(digits) + 1):
for comb in combinations(digits, r):
for perm in permutations(comb):
num = int(''.join(perm))
if num in checked_numbers:
continue
checked_numbers.add(num)
if tub(num):
if min_prime is None or num < min_prime:
min_prime = num
if max_prime is None or num > max_prime:
max_prime = num
return min_prime, max_prime
n = int(input())
input_digits = list(map(str, input().split()))
if not input_digits:
print(0)
else:
min_prime, max_prime = izla(input_digits)
if min_prime is None or max_prime is None:
print(0)
else:
if min_prime==max_prime:
print(min_prime)
else:
if min_prime >= 10:
print(min_prime, end=' ')
else:
min_prime = None
if max_prime:
print(max_prime)
if min_prime is None and (max_prime is None or max_prime < 10):
print(0)
D-masala
Pythonda
import math
def find_character(s, n, k, m):
a = k / 2
b = n + k - k / 2
c = n - m
discriminant = b**2 - 4*a*c
if discriminant < 0:
return 0
x1 = (-b + math.sqrt(discriminant)) / (2 * a)
x2 = (-b - math.sqrt(discriminant)) / (2 * a)
x = max(x1, x2)
if x%1==0:
return s[int(x+1) % len(s)]
return 0
s = input()
n, k, m = map(int, input().split())
result = find_character(s, n, k, m)
print(result)
Yechim |Moynaq IM| --> Isamatdin
s=input()
a1,d,sn=map(int,input().split())
r=10**15+10
l=0
while r-l>0:
mid=(r+l+1)//2
if (2*a1+(mid-1)*d)*mid/2>sn:
r=mid-1
else:
l=mid
if (2*a1+(r-1)*d)*r/2!=sn:
print(0)
exit()
print(s[r%len(s)])
Yechim Test testov