Math
Math
Math
h>
#include <stdlib.h>
#include <time.h>
int main(){
// check if prime is number or not
// counting number of divisors = 2
int n;
int div = 0;
for(int i = 1; i <= n; i++) {
if(n % i == 0) div++;
}
if(div == 2) {
// prime
}
// O(n)
// 45
// 3 divides 45
// 45/3 = 15 divides 45
// i divides n
// n / i also divides n
// sqrt(n)
// i * (n / i) = n
// sqrt(n)
// i * i <= n
// i <= sqrt(n)
// O(sqrt(n))
// n + n / 2 + n / 3 + (n / 4 + n / 5 + n / 6 + n / 7) ........1
// O(n logn)
// n + (n / 2 + n / 2) + (n / 4 + n / 4 + n / 4 + n / 4) +....
// n + (n) + (n)
// n * log(n)
// gcd
// greatest common divisor
// euclidian
// gcd(a, b) = gcd(a, a - b);
// gcd(a, b) = gcd(a, a % b) = gcd(a % b, b)
// gcd(11, 2) = gcd(11, 11 % 2) = gcd(11, 1)
// 45, 15 = 15
// 12, 18 = 6
// 15, 16 = 1 => coprime
// a = 0, b => b
// lcm = a * b / gcd(a, b)
// (a + b) % m = (a % m + b % m) % m;
// (10 + 4) % 3 = (10 % 3 + 4 % 3) % 3 = (1 + 1) % 3 = (2 % 3) = 2
// (a + b + c) % m = ((a % m + b % m) % m + c % m) % m;
// (a - b) % m = (a % m - b % m) % m = (a % m - b % m + m) % m;
// (9 - 12) % 7 = (2 - 5) = -3;
// 1 % 7 = 1....
// +7
// 8 % 7 = 1
// +7
// 15 % 7 = 1
// -1 % 7 = 6
// -7 % 7 = 0
// (a * b) % m = (a % m * b % m) % m;
// (a ^ b) % m = (a * a * a * .......) % m;
// a ^ b = (a ^ (b / 2)) * (a ^ (b / 2));
// b = 10, b / 2 = 5
// b = 11, b / 2 = 5, 5 + 5 = 10, so we add more a to make it 11
// a / b % m = a * (1 / b) = a * (b)^-1
// 7 * (1 / 7) = 1
// x * (y) % m = 1
// m = 7
// x = 3
// y = 1, x * y = 3 % 7 = 3
// y = 2, x * y = 6 % 7 = 6
// y = 3, 9 = 2
// y = 5, x * y = 15 % 7 = 1
// x = 3, modulo inverse of x^(-1) = y = 5
// a / b % m = a * (1 / b) = a * (b)^-1
// when m is prime
// a / b % m = a * inverse_modulo(b) % m
return 0;
}
return gcd(b,a%b);
}
//power function
int binpow(int base , int n)
{
if(expo==0)return 1;
if(n%2==1) return binpow(base,n-1)*base%mod;
if(n%2==0) int temp = binpow(base,n/2); return temp*temp%mod;
}
//inverse function
int inverse(int x)
{
return binpow(x,mod-2);
}
cout<<(ans%mod+mod)%mod<<endl;
ceil(a/b) = floor((a+b-1)/b)
gcd(a,b,c) = gcd(gcd(a,b),c)
==> find gcd of array og numbers
int g = gcd(a[0],a[1]);
for(int i = 2 ;i <n ; i++)
g = gcd(g,a[i]);
cout<<g;