You are on page 1of 7

Exponention2-Qüvvətə yüksəltmə2

def power(x,y,n):
if y==0:
return 1
elif y%2==0:
return power(((x%n)*(x%n))%n, y//2,n)%n
else:
return ((x%n)*(power(((x%n)*(x%n))%n,y//2,n))%n)%n
a,b,n=map(int,input().split())
d=power(a,b,n)
print(d)

The nearest points-ən yaxın nöqtələr


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
vector<pair<int, int> > v;
int a, b, n, x;
scanf("%d", &n);
v.resize(n);
for (int i = 0; i < n; i++)
{
scanf("%d", &x);
v[i] = make_pair(x, i + 1);
}
sort(v.begin(), v.end());
int res = 2e9;
for (int i = 1; i < n; i++)
if (v[i].first - v[i - 1].first < res)
{
res = v[i].first - v[i - 1].first;
a = v[i].second;
b = v[i - 1].second;
}

printf("%d\n%d %d\n", res, a, b);


return 0;
}

The sum of power of two-Iki qüvvətin cəmi


s=input()
l=s.split()
n=int(l[0])
m=int(l[1])
print((1<<n)+(1<<m))

Ardent butterfly Collector- kəpənək Kollektoru


#include<bits/stdc++.h>
using namespace std;
bool binarySearch(int arr[],int k,int l,int r){
if(r >= l){
int mid = (l+r)/2;
if(arr[mid] == k) return true;
else if(arr[mid]>k){
return binarySearch(arr,k,l,mid-1);
}
return binarySearch(arr,k,mid+1,r);
}
return false;
}
int main(){
int n;cin>>n;
int arr[n];
for(int i = 0;i<n;i++){
cin>>arr[i];
}
int m;cin>>m;
for(int i = 0;i<m;i++){
int a;cin>>a;
if(binarySearch(arr,a,0,n)) cout<<"YES\n";
else cout<<"NO\n";
}
}

Square root-kök altı


import java.util.Scanner;
public class Main {
static double f(double x){
return x*x + Math.sqrt(x);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double c = sc.nextDouble();
double left = 0;
double right = c;
while(right-left>1e-10){
double mid = (left+right)/2;
if(f(mid)>c){
right = mid;
}
else left = mid;
}
System.out.printf("%.6f",left);
}
}

Degree of two-İkinin dərəcəsi


n=int(input())
print(2 ** n)
Modular Exponentiation
#include <iostream>
using namespace std;
typedef long long int ll;
ll power(ll x,ll y,ll p)
{
ll res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0)
{
if (y & 1)
res = (res*x) % p;

y = y>>1;
x = (x*x) % p;
}
return res;
}
int main()
{
ll a,b,n;cin>>a>>b>>n;
cout << power(a,b,n);
return 0;
}

2^k + 2^n
k, n = map(int,input().split())
print(2 ** k + 2 ** n)
İnteger Multiplication-Tam ədədlərin vurulması
a,b,m=map(int,input().split())
c=a*b
d = pow(c, 1, m)
print(d)

Modular division- Modul bölmə


def powmod(x,n,m):

if n == 0:

return 1

if n % 2 == 0:

return powmod((x*x)%m,n//2,m)

return (x*powmod(x,n-1,m))%m

a,b,n=map(int,input().split())

y=powmod(b,n-2,n)

x=(a*y)%n

print(x)

if (b*x)%n!=a:

print("error")

Sum of powers 2-Qüvvətlərin cəmi 2


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main() {
ll n,sum = 0,t,m;
cin>>n>>m;
for(int i = 1;i<=n;i++){
t = 1;
for(int j = 0;j<i;j++){
t = (t*i)%m;
}
sum = (sum+t)%m;
}
cout<<sum;
}

You might also like