EKUB va EKUK :: Yechimlar
Masala A
C da itboom.h kutubxonasidagi gcd
funksiyadan ham foydalansa bo’ladi.
Kiritilgan ikkita sonning EKUB qiymatini hisoblaydigan dastur tuzing.
Har bir qatorda \(1\) dan \(2^{63}-1\) gacha bo‘lgan son
Ikkita sonning EKUB qiymati
#include <stdio.h>
#include <itboom.h>
long my_gcd(long n1, long n2) {
n1 = ( n1 > 0) ? n1 : -n1;
n2 = ( n2 > 0) ? n2 : -n2;
long temp;
while (n2 != 0) {
temp = n2;
n2 = n1 % n2;
n1 = temp;
}
return n1;
}
int main() {
long a, b;
scanf("%lld %lld", &a, &b);
printf("%lld", my_gcd(a, b));
// yoki itboom.h dagi funksiyadan foydalanib
// printf("%lld", gcd(a, b));
return 0;
}
import math
import itboom
def main():
a, b = int(input()), int(input())
print(math.gcd(a, b))
if __name__ == '__main__':
main()
Masala B
Kiritilgan ikkita sonning EKUK qiymatini hisoblaydigan dastur tuzing.
Har bir qatorda \(1\) dan \(2^{32}-1\) gacha bo‘lgan son
Ikkita sonning EKUK qiymati
#include <stdio.h>
#include <itboom.h>
int main() {
long a, b;
scanf("%lld %lld", &a, &b);
printf("%lld", a * b / gcd(a, b));
//yoki itboom.h kutubxonasidan foydalanib
//printf("%lld", lcm(a, b));
return 0;
}
import math
import itboom
def main():
a, b = int(input()), int(input())
print(math.lcm(a, b))
if __name__ == '__main__':
main()
Masala C
Kiritilgan sonning tub ko‘paytuvchilari yig‘indisini hisoblaydigan dastur tuzing.
\(2\) dan \(2^{31}-1\) gacha bo‘lgan son
Kiritilgan sonnin tub ko‘paytuvchilari yig‘indisi
#include <stdio.h>
#include <itboom.h>
int main() {
int prime_numbers[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
//yoki qo'lda nechtaligini yozish kerak
int pnn = sizeof(prime_numbers) / sizeof(int);
int n, s = 0;
scanf("%d", &n);
while(n > 1) {
for(int i = 0; i < pnn; i++) {
int p = prime_numbers[i];
if ((n % p) == 0) {
s += p;
n /= p;
}
}
}
printf("%d", s);
return 0;
}
import math
import itboom
prime_numbers = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
def main():
n = int(input())
s = 0
while n > 1:
for p in prime_numbers:
if n % p == 0:
s += p
n //= p
print(s)
if __name__ == '__main__':
main()
Masala D
Kiritilgan son qaysi sonlarning EKUKi ekanligini aniqlaydigan dastur tuzing. Agar bir nechta sonlar juftligi mavjud bo‘lsa, juftliklar ichindan ayirmasining absolut qiymati eng kichik bo‘lgani tanlab olinsin.
\(1\) dan \(2^{31}-1\) gacha bo‘lgan son
Masala shartidagi ikkita son (qatorma-qator). Faqat kichik son birinchi qatorda, katta son ikkinchi qatorda chiqishi lozim.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <itboom.h>
int main() {
int n;
scanf("%d", &n);
for(int i = (int)sqrt(n); i >= 1; i--) {
if (lcm(i, n / i) == n) {
printf("%d\n%d", i, n / i);
break;
}
}
return 0;
}
import math
import itboom
def main():
n = int(input())
for i in range(int(math.sqrt(n)), 0, -1):
if math.lcm(i, n // i) == n:
print(i)
print(n // i)
break
if __name__ == '__main__':
main()
Masala E
Yechimda kiritilgan belgidan 32 ni ayirib keyingi belgi chiqarilgan. ASCII kodlash jadvalida ham kichik va lotin harflari kodlari aynan 32 ga farq qiladi.
Kiritilgan kichik lotin harfni katta lotin harfiga o‘tkazadigan dastur tuzing.
a dan z gacha bo‘lgan harf
Kiritilgan harfning bosh harf shakli
,--------------------------------.