Unnamed Trick 1

Prerequisite Task 1: You are given two array $A$ and $B$ of length $n$. For each $j$ ($0\le j \le n-1$) print $\sum_{i=0}^{j-1}{[A_{i}=B_{j}]}$ In other words, for each $j$($0\le j \le n-1$) print number of index $i$(i<j) where $B_j=A_i$ Constraints click to hide $1\le n \le 10^{5}$ $-10^{9} \le A_{i},B_{i} \le 10^{9}$ cpp map<int, int> cnt; for (int j = 0; j < n; j++) { cout << cnt[B[j]] << '\n'; cnt[A[j]]++; } Prerequisite Task 2: Same as task 1, just find $\sum_{j=0}^{n-1}{\sum_{i=0}^{j-1}{[A_{i}=B_{j}]}}$
Read more →

Leading and Trailing - UVA 11029

For given $n$ and $m$ print the value LLL...TTT where LLL is the leading $3$ digits of $n^{m}$ and TTT is trailing $3$ digits of $n^{m}$. Inside Math: For TTT we just use modular arithmetic and find $n^{m} \text{ (mod 1000)}$ Now, assume that , number of digit of $n^{m}$ is $x$. Hence LLL must be equals to $\lfloor \frac{n^{m}}{10^{x-3}}\rfloor$ How to find x ? click to hide \begin{align} 10^{x-1} \le n^{m} &< 10^{x} \text{ [Number of digit in }10^{x-1}\text{ is equals to }x\text{ ]}\newline log_{10}{10^{x-1}} \le log_{10}{n^{m}} &< log_{10}{10^{x}} \newline x-1 \le m \times log_{10}{n} &< x \newline x &\le m \times log_{10}{n} + 1 \newline \therefore\text{maximum possible integer value of }&x\text{ is }\lfloor m \times log_{10}{n} + 1 \rfloor\text{ or }\lfloor m \times log_{10}{n} \rfloor +1 \end{align} But how to calculate $\lfloor \frac{n^{m}}{10^{x-3}}\rfloor$ ?
Read more →

Modular Arithmetic: Introductory Problems

Problems on basics of modular arithmetic
Read more →

Modular Arithmetic: Introduction

Basics of modular arithmetic
Read more →