You declared 'q' twice in your code, both on the 21st line and the 24th line. Can anyone please explain why didn't it receive a compilation error for this redeclaration?
Please tell me that how do determine the complexity here in first in which you say that t must run under logn or 1 to run the algo of this question ⁉️???
outer loop runs n time and inner loop for a particular number i it runs n/I times so ,basically for 1 inner loop runs n/1,for 2 it is n/2 ...for I it is n/I so on...for n its n/n..hence total no of iterations would be n/1 + n/2 + n/3 + ...+ n/n = nlogn(you can checkout on the internet that how this sum is nlogn)..Hence tc would be O(nlogn)..
Can anyone tell me what's the problem with this code? Six test cases are not passing? #include using namespace std; const int N = 2e5 + 10; int hsh[N]; int cnt[N]; int main() { int n; cin >> n ; for(int i=0; i> x; hsh[x]++; } for(int i = 1; i < N; ++i){ for(int j = i; j < N; j += i){ cnt[i] += hsh[j]; } } int t; cin >> t; while(t--){ int p,q; cin >> p >> q; long long lcm = (p * q * 1LL) / __gcd(p,q); long long ans = cnt[p] + cnt[q]; if(lcm < N){ ans -= cnt[lcm]; } cout
have written same code but my code is failing at case 5,6,7,12,13,14 error is runtime error please have a look at my code and tell problem #include #include using namespace std; const int Nmax = 2e5 + 10; int mp[Nmax]; int total_multiple_present[Nmax]; int main() { // takin count of element present in array int N; cin >> N; for (int i = 0; i < N; i++) { int ele; cin >> ele; mp[ele]++; } //makin total_multiple arry //as every element will be divisible by 1 for (int i = 1; i < Nmax; i++) { for (int j = i; j < Nmax; j += i) { total_multiple_present[i] += mp[j]; } } //takin no of queries int t; cin >> t; //for (auto it : total_multiple_present) cout p >> q; // lcm can overflow int range so use long long long long lcm = (p * q) * 1LL / __gcd(p, q); // total no in array divisible by p,q or pqboth will be no(p)+no(q)-no(lcm_of_P_q) long ans = total_multiple_present[p] + total_multiple_present[q]; if (lcm < Nmax) ans -= total_multiple_present[lcm]; // cout
Didn't know we can use sieve in such ways 😲, very informative video 🙇♂️
Best cp course on UA-cam ❤
If this is a easy-medium question then i don't know what a hard question will look like!😲😲
multiples_ct[i] += hash[j]; // this logic is just wow!
Hats off to the way you solved the problem...
Growing faster 💪💪💪
Number divisible by p+number divisible by q+number divisible by lcm(p+q).
time complexity will still be N^2, right? could it have been done by simply checking divisibility of numbers till N for numbers in array?
uh r the best bro..
took me a while to understand but got it.
Thanks bhaiya
Thanks 😊
27 march 2022 4:45 pm
bro Y R U not uploading videos !?? we all R dead waiting for ur videos...
Loved it bhiya
Thank you
You declared 'q' twice in your code, both on the 21st line and the 24th line. Can anyone please explain why didn't it receive a compilation error for this redeclaration?
Please tell me that how do determine the complexity here in first in which you say that t must run under logn or 1 to run the algo of this question ⁉️???
check the sieve tutorial video i have explained sieve related time complexity there
@@iamluv okk
Bhaiya koi index type ka bhi de do kis time pe konsa topic karaoge schedule type ka khuchh
Bro will you cover bitwise sieve in your course?
Sir code kis app par karte hai
Great
Please make a video on oops in c++
nice
Hello love sir
Cool
What if you just put all the values in a set and then returned its value.....
🙌🙌🙌👏
Harsh Sharma User C Nesting
Bro please upload full course in data structures
💛🧡❤🧡💛
Can anyone tell how complexity of seive loop is not n^2 please??🙂
outer loop runs n time and inner loop for a particular number i it runs n/I times so ,basically for 1 inner loop runs n/1,for 2 it is n/2 ...for I it is n/I so on...for n its n/n..hence total no of iterations would be n/1 + n/2 + n/3 + ...+ n/n = nlogn(you can checkout on the internet that how this sum is nlogn)..Hence tc would be O(nlogn)..
sir stl ke questions dedo sir and pls make a video on hashmap🙏
Can anyone tell me what's the problem with this code?
Six test cases are not passing?
#include
using namespace std;
const int N = 2e5 + 10;
int hsh[N];
int cnt[N];
int main() {
int n;
cin >> n ;
for(int i=0; i> x;
hsh[x]++;
}
for(int i = 1; i < N; ++i){
for(int j = i; j < N; j += i){
cnt[i] += hsh[j];
}
}
int t;
cin >> t;
while(t--){
int p,q;
cin >> p >> q;
long long lcm = (p * q * 1LL) / __gcd(p,q);
long long ans = cnt[p] + cnt[q];
if(lcm < N){
ans -= cnt[lcm];
}
cout
Hello sir
I am first
@Saksham Sharma okay bro
2dj0y
#vur.fyi
have written same code but my code is failing at case 5,6,7,12,13,14 error is runtime error
please have a look at my code and tell problem
#include
#include
using namespace std;
const int Nmax = 2e5 + 10;
int mp[Nmax];
int total_multiple_present[Nmax];
int main()
{
// takin count of element present in array
int N;
cin >> N;
for (int i = 0; i < N; i++)
{
int ele;
cin >> ele;
mp[ele]++;
}
//makin total_multiple arry
//as every element will be divisible by 1
for (int i = 1; i < Nmax; i++)
{
for (int j = i; j < Nmax; j += i)
{
total_multiple_present[i] += mp[j];
}
}
//takin no of queries
int t;
cin >> t;
//for (auto it : total_multiple_present) cout p >> q;
// lcm can overflow int range so use long long
long long lcm = (p * q) * 1LL / __gcd(p, q);
// total no in array divisible by p,q or pqboth will be no(p)+no(q)-no(lcm_of_P_q)
long ans = total_multiple_present[p] + total_multiple_present[q];
if (lcm < Nmax) ans -= total_multiple_present[lcm]; //
cout
(p * 1LL * q) : write in this way, p*q*1LL is same as p*q
or use both long long