### AJAYHAYAGREEVE's blog

By AJAYHAYAGREEVE, history, 7 months ago, ,

hi guys, Am trying to solve this problem (http://codeforces.com/problemset/problem/526/C). My approach is find the lcm of w1 and w2. Now on reaching lcm(w1, w2) if(lcm/w1*h1 > lcm/w2*h2) then we prefer h1 upto the lcm. else we prefer h2 Now for the remaining i.e from c/lcm to c, Just iterate and check which is the optimal answer. My code is https://ide.geeksforgeeks.org/zh4C5tHJPG . But i get wrong answer on test 3. I couldnot figure out what is wrong. Could you help me.

By AJAYHAYAGREEVE, history, 7 months ago, ,

Hi guys, Am trying to solve the problem 492 D. http://codeforces.com/problemset/problem/492/D. My approach is use binary search, to find the index at which the monster dies. My solution is https://ide.geeksforgeeks.org/Dcs5Fn6w2S. But i got wrong answer in test 7. so i changed the equal function to compare upto 10^-6. Then i got wrong answer on test 6. Can someone plz tell me why this method fails.

By AJAYHAYAGREEVE, history, 8 months ago, ,

hi every one. im having a doubt in codeforces problem 440 C. here is the link http://codeforces.com/problemset/problem/440/C. My approach was

A number x can be represented by having the number with only ones which is less than the given number. for eg if number is 40 one approach is taking 11.

Another is having the number with only ones which is greater than the given number. i.e. 111 for 40 then take absolute difference between the number and the given number i.e abs(11 – 40) = 29 and abs(111 – 40) which is 71.

Now call the function again for the new n. in this case fun(29) and fun(49).

Now added with the number of ones take the min of these two i.e min(fun(29) + 2, fun(71) + 3). that is the answer. Also if we can represent the number with the ones alone. for eg 11 then return 2 just. i.e without computing min(fun(11-11) + 2, fun(111- 11) + 3);

But i got wrong answer in test 14. the input is 81924761239462. and the expected output is 321. And my output is 395. Can you please tell me what is wrong.

here is the link: http://ide.geeksforgeeks.org/kRLASR. And even in diagnostics it is not showing anything.

•
• -5
•

By AJAYHAYAGREEVE, history, 8 months ago, ,

hi every one. im having a doubt in codeforces problem 440 C. here is the link http://codeforces.com/problemset/problem/440/C. My approach was

A number x can be represented by having the number with only ones which is less than the given number. for eg if number is 40 one approach is taking 11.

Another is having the number with only ones which is greater than the given number. i.e. 111 for 40 then take absolute difference between the number and the given number i.e abs(11 – 40) = 29 and abs(111 – 40) which is 71.

Now call the function again for the new n. in this case fun(29) and fun(49).

Now added with the number of ones take the min of these two i.e min(fun(29) + 2, fun(71) + 3). that is the answer. Also if we can represent the number with the ones alone. for eg 11 then return 2 just. i.e without computing min(fun(11-11) + 2, fun(111- 11) + 3);

But i got wrong answer in test 14. the input is 81924761239462. and the expected output is 321. And my output is 395. Can you please tell me what is wrong.

•
• -3
•

By AJAYHAYAGREEVE, history, 9 months ago, ,

hi everyone. I'm having a doubt in problem 839D. The link is here http://codeforces.com/problemset/problem/839/D
I submitted a solution which gives me wrong answer on test 44. The link is here. https://ideone.com/tJhWMt

But i just modified the line number 57 from ans[i] = gcd[i] * p2[max(gcd[i] — 1, (int)0)]; to
ans[i] = (gcd[i] * p2[max(gcd[i] — 1, (int)0)]) % mod; where mod is 10^9 + 7. And it got accepted

My question is even though we don't take the mod value in line 59, in line number 60 after the execution of the 1st inner for on line 59, it will automatically take modulus and by any means ans[i*j], on line 60 wont be greater than 10^9 + 6. So why is the mod on line 57 even necessary. Plz help. Thanks in advance