πŸ‘¨β€πŸ³Basic Math - Codechef

Q1:

The chef wants to become fit for which he decides to walk to the office and return home by walking. It is known that Chef's office is X km away from his home.

If his office is open 5 days a week, find the number of kilometers the Chef travels through office trips in a week.

#include <iostream>
using namespace std;

int main() {
	int X;
	int tt;
	cin >> tt;
	while(tt--) {
	    cin>>X;
	    cout << (X*2)*5 << endl;
	}
	return 0;
}

Segmented Sieve

Q2: Must read -> Euclid GCD Algorithm

GCD Formula: Find gcd until one of the parameters becomes zero

gcd(a - b, b)

gcd(a % b, b)

LCM & GCD Relation: LCM(a, b) * GCD(a, b) = a * b

( a%m + b%m) % m = (a + b) % m

(a%m βˆ’ b%m) % m = (a βˆ’ b) % m

(a%m * b%m) % m = (a * b) % m

Q3: Modular Exponentiation --> Notes Page # 05

Using Fast Exponentiation Algorithm T.C: O(logn)

Last updated

Was this helpful?