👨‍🍳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

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

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

Last updated