π¨βπ³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;
}Q1: Count Prime
Q1: Count PrimeSegmented 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
Topic: Modular Arithmetic
( 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
Q3: Modular Exponentiation --> Notes Page # 05Using Fast Exponentiation Algorithm T.C: O(logn)
Last updated
Was this helpful?