Given an array A of size n.count the number of pairs such that A[i]*A[j]==A[i]+A[j]. Since the constraint of A[i] is upto 10^9 and N is upto 40,000 , I cannot run the naive technique of running a double loop. Any other way to solve it in one loop?
№ | Пользователь | Рейтинг |
---|---|---|
1 | ecnerwala | 3648 |
2 | Benq | 3580 |
3 | orzdevinwang | 3570 |
4 | cnnfls_csy | 3569 |
5 | Geothermal | 3568 |
6 | tourist | 3565 |
7 | maroonrk | 3530 |
8 | Radewoosh | 3520 |
9 | Um_nik | 3481 |
10 | jiangly | 3467 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | maomao90 | 174 |
2 | adamant | 164 |
2 | awoo | 164 |
4 | TheScrasse | 160 |
5 | nor | 159 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 150 |
8 | SecondThread | 147 |
9 | orz | 146 |
10 | pajenegod | 145 |
Given an array A of size n.count the number of pairs such that A[i]*A[j]==A[i]+A[j]. Since the constraint of A[i] is upto 10^9 and N is upto 40,000 , I cannot run the naive technique of running a double loop. Any other way to solve it in one loop?
Название |
---|
A[i] * A[j] = A[i] + A[j]
A[i] — A[i] * A[j] + A[j] = 0
A[i] * (1 — A[j]) + A[j] = 0
A[i] = A[j] / (1 — A[j])
if numbers are integers u need just to count pairs of (2, 2), (0, 0) else just use map like:
the only valid pairs values are (0, 0) and (2, 2), so just count the number of twos and zeros, the result ist binom(zeros, 2)+binom(twos, 2)
A[i]*A[j]-A[i]=A[j]
A[i] = A[j]/(A[j]-1)
if A[j] % (A[j]-1) = 0 then we can find A[i] such that given condition satisfy & there are only two such interger 0 & 2.
let say, cnt1 = total 0s & cnt2 = total 2s
so answer will be cnt1*(cnt1 -1)/2 + cnt2*(cnt2 -1)/2
Please refrain from answering this question. This is from ongoin long challenge of codechef- https://www.codechef.com/DEC19B/problems/PLMU
lol cheatin' eh? It's from codechef long challenge.
I request the community to answer questions only if links are provided or atleast if it is posted from a genuine account. It feels really bad seeing the questions and solutions posted like this.