New course! Every coder should learn Generative AI!
Try a free lesson+ 6
Why the outermost loop? Are you supposed to repeat the process n times?
+ 4
Since you are doing in hacker rank I think it's for competitive programmers so your output should be given as fast as possible .As I remember ,you have to give output within 2 sec.
Since your code is taking time that's why they are showing runtime error.
My suggestion try to make your logic strong.
+ 2
AteFish🇧🇩 in sololearn I can see output:
https://code.sololearn.com/cja1eD0L0h7l/?ref=app
+ 2
It should give multiple output.
because you declared while(n--)
+ 2
AteFish🇧🇩
if I write
2
5
6
what will be the expected output you should get according to the question?(I am asking because I don't know the question)
+ 2
AteFish🇧🇩 ,Your code is working on first case.
+ 2
AteFish🇧🇩 also works in codeblocks .
+ 2
Namit Jain ,something is different 🤔.I have copied and pasted atefish code but I can see right answer:
https://code.sololearn.com/cja1eD0L0h7l/?ref=app
+ 2
Namit Jain ,
Input formate:
1//number of test case
111/the number
Output:
3
I have tried your code:
1
111
the output is 6 .
In atefish code the output is 3.
+ 2
Namit Jain ,
Karnet Number a number which is a factor of every digit is has...
Such as 126 is a karnet number cause 1 is a factor of 126
2 is also and 6 is also
We have to print how many times the number % digit ==0
Just need to check the reminder of bigger number and his digit.
+ 2
AteFish🇧🇩 not solved?
+ 2
AteFish🇧🇩 121%1=0
121 is a number
Number%digit=0
121%1(1st digit)=0
121%2(2nd digit)=1
121%1(2nd digit)=0
As we see there are 2 factors of 121 of digits so output 3
not 3 answer 2 (if input 121)
+ 2
AteFish🇧🇩
i think you should not used n— in while loop. i cleaned up your code, and it does nit produce any runtime error anymore. also, for me avoid using ? ternary operator. here is my code pls tell me if it not produces runtime anymore in your laptop
https://code.sololearn.com/cl1f74570W5G/?ref=app
+ 2
Just trying to do it without vector.
But it is way longer 😂
https://code.sololearn.com/cyxzGa6z8O8h/?ref=app
+ 1
Did you mind the constraints of the problem?
+ 1
AteFish🇧🇩 problem link ?
+ 1
AteFish🇧🇩 Error not coming in your code but:
The output is wrong! As far as I understand the question 🤔
I have made this code!
Check it out and it will work for any number of digits
(Sorry donno C++)
If you want the C++ version of this code then pls tell! I ll have to search for the syntaxes on Google
https://code.sololearn.com/cbyfp9AuXMHl/?ref=app
+ 1
Samsil Arefeen Try to enter: 226 and 634
+ 1
Samsil Arefeen
1 1 1
Place1 Place2 Place3
Case1: Place1 % Place2 = 0 1
Case2: Place1 % Place3 = 0 +1
Case1: Place2 % Place1 = 0 +1
Case2: Place2 % Place3 = 0 +1
Case1: Place3 % Place1 = 0 +1
Case2: Place3 % Place2 = 0 +1
= 6
What's the problem?