Tech Jargon - Decoded
الذهاب إلى القناة على Telegram
Confused by tech terms? Don’t worry, we’ve got you 🤝 We make things simple, one concept at a time. Learn daily Easy & clear Turn Confusion into clarity. #tech #it #softwareengineer #cs #development
إظهار المزيد2 015
المشتركون
-124 ساعات
-57 أيام
-4030 أيام
أرشيف المشاركات
Modular Exponentiation
public class ModularExponentiation {
public static long modularExponentiation(long base, long exponent, long modulus) {
long result = 1;
base = base % modulus;
while (exponent > 0) {
if (exponent % 2 == 1) {
result = (result * base) % modulus;
}
base = (base * base) % modulus;
exponent = exponent >> 1;
}
return result;
}
public static void main(String[] args) {
long base = 2;
long exponent = 10;
long modulus = 1000;
long result = modularExponentiation(base, exponent, modulus);
System.out.println("Result: " + result);
}
}Modular Multiplicative Inverse
public class ModularInverse {
public static int modInverse(int a, int m) {
if (gcd(a, m) != 1) {
return -1; // Inverse doesn't exist
}
return power(a, m - 2, m);
}
// Function to calculate (a^b) % m
static int power(int a, int b, int m) {
int res = 1;
a = a % m;
while (b > 0) {
if ((b & 1) == 1)
res = (res * a) % m;
a = (a * a) % m;
b >>= 1;
}
return res;
}
// Function to calculate gcd(a,b)
static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
public static void main(String[] args) {
int a = 3;
int m = 11;
int inverse = modInverse(a, m);
if (inverse != -1) {
System.out.println("Modular multiplicative inverse of " + a + " under modulo " + m + " is " + inverse);
} else {
System.out.println("Modular multiplicative inverse doesn't exist.");
}
}
}Modular Exponentiation
public class ModularExponentiation {
public static long modularExponentiation(long base, long exponent, long modulus) {
long result = 1;
base = base % modulus;
while (exponent > 0) {
if (exponent % 2 == 1)
result = (result * base) % modulus;
exponent = exponent >> 1;
base = (base * base) % modulus;
}
return result;
}
public static void main(String[] args) {
long base = 2;
long exponent = 10;
long modulus = 1000;
long result = modularExponentiation(base, exponent, modulus);
System.out.println("Result: " + result);
}
}Modular Multiplicative Inverse
public class ModularInverse { public static int modInverse(int a, int m) { a = a % m; for (int x = 1; x < m; x++) { if ((a * x) % m == 1) { return x; } } return -1; } public static void main(String[] args) { int a = 3; int m = 11; int inverse = modInverse(a, m); if (inverse != -1) { System.out.println("Modular multiplicative inverse of " + a + " under modulo " + m + " is " + inverse); } else { System.out.println("Modular multiplicative inverse doesn't exist for " + a + " under modulo " + m); } }}Modular Exponentiation
public class ModularExponentiation { public static long modularExponentiation(long base, long exponent, long modulus) { long result = 1; base = base % modulus; while (exponent > 0) { if (exponent % 2 == 1) { result = (result * base) % modulus; } exponent = exponent >> 1; base = (base * base) % modulus; } return result; } public static void main(String[] args) { long base = 2; long exponent = 10; long modulus = 1000; long result = modularExponentiation(base, exponent, modulus); System.out.println("Result: " + result); }}Check Pythagorean Triplets
public class PythagoreanTriplet {
public static boolean isPythagoreanTriplet(int a, int b, int c) {
int[] nums = {a, b, c};
java.util.Arrays.sort(nums);
return nums[0] * nums[0] + nums[1] * nums[1] == nums[2] * nums[2];
}
public static void main(String[] args) {
System.out.println(isPythagoreanTriplet(3, 4, 5)); // true
System.out.println(isPythagoreanTriplet(1, 2, 3)); // false
System.out.println(isPythagoreanTriplet(5, 12, 13)); // true
}
}Sieve of Eratosthenes
public class SieveOfEratosthenes {
public static boolean[] sieve(int n) {
boolean[] isPrime = new boolean[n + 1];
for (int i = 2; i <= n; i++) {
isPrime[i] = true;
}
for (int p = 2; p * p <= n; p++) {
if (isPrime[p]) {
for (int i = p * p; i <= n; i += p) {
isPrime[i] = false;
}
}
}
return isPrime;
}
public static void main(String[] args) {
int n = 30;
boolean[] primes = sieve(n);
for (int i = 2; i <= n; i++) {
if (primes[i]) {
System.out.println(i + " is prime");
}
}
}
}Sieve of Eratosthenes
public class SieveOfEratosthenes {
public static boolean[] sieve(int n) {
boolean[] isPrime = new boolean[n + 1];
for (int i = 2; i <= n; i++) {
isPrime[i] = true;
}
for (int p = 2; p * p <= n; p++) {
if (isPrime[p]) {
for (int i = p * p; i <= n; i += p) {
isPrime[i] = false;
}
}
}
return isPrime;
}
public static void main(String[] args) {
int n = 30;
boolean[] primes = sieve(n);
for (int i = 2; i <= n; i++) {
if (primes[i]) {
System.out.println(i + " is prime");
}
}
}
}Sieve of Eratosthenes
public class SieveOfEratosthenes {
public static int[] findPrimes(int limit) {\n boolean[] isPrime = new boolean[limit + 1];
for (int i = 2; i <= limit; i++) {
isPrime[i] = true;
}
for (int p = 2; p * p <= limit; p++) {
if (isPrime[p]) {
for (int i = p * p; i <= limit; i += p) {
isPrime[i] = false;
}
}
}
int primeCount = 0;
for (int i = 2; i <= limit; i++) {
if (isPrime[i]) {
primeCount++;
}
}
int[] primes = new int[primeCount];
int index = 0;
for (int i = 2; i <= limit; i++) {
if (isPrime[i]) {
primes[index++] = i;
}
}
return primes;
}
public static void main(String[] args) {
int limit = 30;
int[] primes = findPrimes(limit);
for (int prime : primes) {
System.out.print(prime + " ");
}
System.out.println();
}
}Sieve of Eratosthenes
public class SieveOfEratosthenes {
public static boolean[] sieve(int n) {
boolean[] isPrime = new boolean[n + 1];
for (int i = 2; i <= n; i++) {
isPrime[i] = true;
}
for (int p = 2; p * p <= n; p++) {
if (isPrime[p]) {
for (int i = p * p; i <= n; i += p) {
isPrime[i] = false;
}
}
}
return isPrime;
}
public static void main(String[] args) {
int n = 30;
boolean[] primes = sieve(n);
for (int i = 2; i <= n; i++) {
if (primes[i]) {
System.out.println(i + " is prime");
}
}
}
}
متاح الآن! بحث تيليغرام 2025 — أهم رؤى العام 
