A. Teskari^2

Python dasturlash tilidagi yechim:

n = int(input())
if n % 10 > 0 or n == 0:
    print(1)
else:
    print(0)

C++ dasturlash tilidagi yechim:

#include <iostream>
using namespace std;


int main() {
    int n;
    cin >> n;
    if (n % 10 > 0 || n == 0) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

B. Operatsiyalar soni

Python dasturlash tilidagi yechim:

a, b = map(int, input().split())
if a < b:
    a, b = b, a
c = 0
while (b > 0):
    c += a // b
    a %= b
    if a < b:
        a, b = b, a
print(c)

C++ dasturlash tilidagi yechim:

#include <iostream>
using namespace std;


int main() {
    int a, b;
    cin >> a >> b;
    if (a < b) {
        a = a + b;
        b = a - b;
        a = a - b;
    }
    int c = 0;
    while (b > 0) {
        c += a / b;
        a %= b;
        if (a < b) {
            a = a + b;
            b = a - b;
            a = a - b;
        }
    }
    cout << c << endl;
    return 0;
}

C. Sakrashlar soni

Python dasturlash tilidagi yechim:

x = int(input())
x = abs(x)
ans = 0
while True:
    s = ans * (ans + 1) / 2
    if (s >= x and (s - x) % 2 == 0):
        break
    ans += 1
print(ans)


C++ dasturlash tilidagi yechim:

#include <iostream>
#include <cmath>
using namespace std;


int main() {
    int x;
    cin >> x;
    x = abs(x);
    int ans = 0;
    while (true) {
        int s = ans * (ans + 1) / 2;
        if (s >= x && (s - x) % 2 == 0) {
            break;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

D. Eng kichik bo'luvchi

Python dasturlash tilidagi yechim:

n = int(input())
i = 2
while i * i <= n:
    if n % i == 0:
        print(i)
        exit(0)
    i += 1
print(n)


C++ dasturlash tilidagi yechim:

#include <iostream>
using namespace std;


int main()
{
    long long n;
    cin >> n;
    long long i = 2;
    while (i * i <= n)
    {
        if (n % i == 0)
        {
            cout << i << endl;
            return 0;
        }
        i += 1;
    }
    cout << n << endl;
    return 0;
}

E. Musiqaxo'r

Python dasturlash tilidagi yechim:

n = int(input())
a = list(map(int, input().split()))
mp = {}
ans = 0
l = 0
for i in range(n):
    x = a[i]
    if x in mp:
        l = max(l, mp[x] + 1)
        ans = max(i - l + 1, ans)
        mp[x] = i
    else:
        mp[x] = i
        ans = max(i - l + 1, ans)
print(ans)


C++ dasturlash tilidagi yechim:

#include <iostream>
#include <vector>
#include <map>
using namespace std;


int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int ans = 0, l = 0;
    for (int i = 0; i < n; i++)
    {
        int x = a[i];
        if (mp.find(x) != mp.end())
        {
            l = max(l, mp[x] + 1);
            ans = max(i - l + 1, ans);
            mp[x] = i;
        }
        else
        {
            mp[x] = i;
            ans = max(i - l + 1, ans);
        }
    }


    cout << ans;
}

 

Savol va takliflar: Chat