Posts

Showing posts with the label Solved

Exponentiation Solution C++ : CSES Problem Set

CSES Problem Set Exponentiation TASK SUBMIT RESULTS STATISTICS HACKING Time limit: 1.00 s Memory limit: 512 MB Your task is to efficiently calculate values a^b modulo 10^9+7. Note that in this task we assume that 0^0=1. Input The first input line contains an integer n: the number of calculations. After this, there are n lines, each containing two integers a and b. Output Print each value a^b modulo 10^9+7. Constraints1 \le n \le 2 \cdot 10^5 0 \le a,b \le 10^9 Example Input:3 3 4 2 8 123 123 Output:81 256 921450052 Link to this code: https://cses.fi/paste/ced3e665267b063471beea/ #include <bits/stdc++.h> #include <iostream> #include <iomanip> #include <cmath> #include <string> #define MOD 1000000007 #define ell cout<<endl #define el endl #define pi 3.14159 #define forn(i, n) for (int i = 0; i < int(n); i++) #define ll long long #define ull unsigned long long #define ld long double #define vll vector<ll> #define pll pair<ll,ll> #de...

112. a^b-b^a - Codeforces || You are given natural numbers a and b. Find a^b-b^a. Codeforces

  112. a^b-b^a https://codeforces.com/problemsets/acmsguru/problem/99999/112 time limit per test: 0.25 sec. memory limit per test: 4096 KB You are given natural numbers a and b. Find a^b-b^a.  Input Input contains numbers a and b (1≤a,b≤100). Output Write answer to output. Sample Input 2 3 Sample Output -1 Solution Code: C++ #include <iostream> #include <cmath> // solved the problem but not accepted with this code... // i got accepted with the python code. int main () { int a, b; std::cin >> a >> b; long long pa = pow (a, b); long long pb = pow (b, a); std::cout << pa - pb << std::endl; return 0 ; } Solution Code: Python 3 # Accepted a,b = map ( int , input ().split()) pa = pow (a,b) pb = pow (b,a) print (pa - pb)

Way Too Long Words - Codeforces problem solution

 Way Too Long Words - Codeforces problem solution  A. Way Too Long Words Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input...

ICPC Dhaka Regional Preliminary Contest #Editorials 2022 Hosted By Green University of Bangladesh

  ICPC Dhaka Regional Preliminary Contest 2022 Hosted By Green University of Bangladesh Problem A: A Game with Grandma Setter: Shafaet Ashraf Tester & Alter writers: Nafis Sadique Aleksa Plavsic Arghya Pal Problem type: Game Theory, DP Solution idea: If you're familiar with Grundy Numbers, you can use the divide and conquer technique to solve it. To do this, loop through the columns of the grid and place a box in all possible positions. Whenever a box is placed, it divides the whole grid into two parts. Solve each sub-problem recursively by calculating the Grundy number. The base case is when the grid size is less than 1. This solution has a time complexity of O(N^3) and will pass the time limit. Problem B: Transform the Array Setter: Raihat Zaman Neloy Tester & Alter writers: Md. Mahbubul Hasan H. M. Ashiqul Islam Muhiminul Islam Osim Problem type: Number theory, finding prime divisors Solution idea: For the first type of transformation - Let's find two sets of primes ...

Popular posts from this blog

Callback function in JavaScript

Using Generic in TypeScript about types in the Code

12 Best Websites to Practice Coding for Beginners