Modulo - Toph

You will be given an array, $A$ of length $n$ and $q$ queries. In each query you will be given a value $x$. You have to perform $A_{i} = A_{i} \text{ (mod $x$)} , 1 \le i \le n$ for each query , and after all the query print the array. Constraints click to hide $A_{i} \le 2^{60}$ $n\le 10^{5}$ $q\le 10^{5}$ $x \le 2^{60}$ Solution: When $A_{i} = A_{i} \text{ (mod $x$)}$ operation change $A_{i}$ ?
Read more →

Gift Dilemma - UVA 12775

$Ax+By+Cz=P$ , $0\le x,y,z$ and $200 \le \frac{C}{gcd(A,B,C)}$. For given $A,B,C,P$ find number of triplet $(x,y,z)$. Solution: \begin{align} 200 &\le \frac{C}{gcd(A,B,C)} \newline C &\ge 200\times gcd(A,B,C) \newline \therefore C &\ge 200 \end{align} Hence, we will rewrite the eqation as $Ax+By+Cz=P \Longrightarrow Ax+By=P-Cz=P'$ We will iterate over all possible values of $P'$(there will be maximum $\frac{10^{8}}{200}$), and for each value of $P'$ we will find number of pair $(x,y)$ that satisfy $Ax+By=P'$ , and sum them up.
Read more →

Long Sandwich - Codechef SANDWICH

It has two parts to this problem. You are given $n$ and $k$. You have to tell the minimum number of pieces, $a$, you can cut a sandwich of length $n$ such that the length of no piece is greater than $k$. The answer is quite simple, isn’t it ? Answer of the first part click to hide $a = \lceil \frac{n}{k} \rceil$ The second part is, how many ways we can cut the sandwich into $a$ pieces such that the length of no piece is greater than $k$.
Read more →

Fraction and Sequence - UVA 13041

How many triplet $(a,b,c)$ are there such that $0\le a,b,c \le L$ and $\sum_{x=0}^{\infty}{(ax^{2}+bx+c)\times (\frac{1}{10})^{x+1}} = \frac{p}{q}$ , for given $p,q,L$. Inside Math: Suppose, $A = \sum_{x=0}^{\infty}{ax^2\times (\frac{1}{10})^{x+1}}$ $B = \sum_{x=0}^{\infty}{bx\times (\frac{1}{10})^{x+1}}$ $C = \sum_{x=0}^{\infty}{c\times (\frac{1}{10})^{x+1}}$ Hence, $\sum_{x=0}^{\infty}{(ax^{2}+bx+c)\times (\frac{1}{10})^{x+1}} = A+B+C$ Now, we know(Actually we don’t know this, we have to prove this. We’ll try to prove this in some other section) that: $\sum_{x=0}^{\infty}{x^{2}r^{x+1}} = \frac{r^{2}(r+1)}{(r-1)^{3}} \tag{1}$ $\sum_{x=0}^{\infty}{xr^{x+1}} = \frac{r^{2}}{(r-1)^{2}} \tag{2}$
Read more →

Primes or Palindromes? - Codeforces - 568a

$\pi(n) = \text{ number of prime number smaller than or equal to n}$ . $rub(n) = \text{ number of palindromic number smaller than or equal to n}$ . For a given $p$ and $q$ find maximum such $n$ so that, $\pi(n)\le \frac{p}{q}\times rub(n)$ Inside Math: $\pi(n) \approx \frac{n}{ln(n)}$ [Prime number approximation] $rub(n) \approx 2\sqrt{n}$ maximum value of $\frac{p}{q} = 42$ Hence , \begin{align} \pi(n) &\le \frac{p}{q}\times rub(n) \newline \Longrightarrow \frac{n}{ln(n)} &\le 42 \times 2\sqrt{n} \newline \Longrightarrow \frac{\sqrt{n}}{ln(n)} &\le 84 \newline \Longrightarrow n_{max} &\approx \boxed{1415344} \newline \end{align}
Read more →

Complex Tashreef - Toph

Statement: In this problem you are asked to calculate : $\sum_{i=L}^{R}{\sum_{j=0}^{i}{[\binom{i}{j} \text{ (mod 2)} \equiv 0]}}$ , for given $L$ and $R$. Inside Math: From the lucas' theorem we can state that, $\sum_{j=0}^{i}{[\binom{i}{j} \text{ (mod 2)}\equiv 1]} = 2^{f(i)}$ . [$f(i) = \text{ number of one in binary representation of } i$] Suppose , $S(x) = \sum_{i=0}^{x}{\sum_{j=0}^{i}{[\binom{i}{j} \text{ (mod 2)} \equiv 0]}}$ . Hence , our answer will be $S(R)-S(L-1)$
Read more →

Divisors - UVA 294

In this problem we will run a segmented sieve for [l,r]. In sieve we will maintain “number of divisor of $n$ which is smaller or equal than $\sqrt{n}$". For each, $i\in [1,\sqrt{r}]$ we will increase number of divisor of each multiple of $i$ in range $[max(l,i^2),r]$. After the sieve we will multiply $2$ with each number of divisor, because if $i$ is a divisor of $n$ such that $i\le \sqrt{n}$ , we will have another divisor $\frac{n}{i} \ge \sqrt{n}$.
Read more →

Prime Factor Love - Toph

Find sum of sum-of-divisor from 1 to n
Read more →

Divisor Set - Codeforces - 1257g

knapsack dp with ntt
Read more →