Greatest Common Divisor

Back to General discussions forum

vtivadze     2017-07-16 10:24:49

Hello Admin... :)

I've tried to solve a problem "Greatest Common Divisor" on PHP and by my opinion I've done it because my version of solution works on my local server (I've only presented input data as an array) and it returns correct values (I've comparead them with your answers twice).

As I've noticed the problem appears during getting input data but the method that I've used for getting input data worked perfectly for earlier problems.

So I can't understand what to do.

Can you help me please?

Quandray     2017-07-16 11:12:05
User avatar

Hi,

I know little about PHP. (Admin probably knows more, but he hasn't been around for a long time)

The first line of the input contains the number of test cases. It would be easier to help you if your code read that value, and then processed that number of test cases.

I tried your code with the example data and it worked (as long as there wasn't a blank line at the end). When I tried it with a few more test cases I got
Please wait upto 20 seconds
then that was replaced with
No syntax errors detected in solution.php

I think it's doing that because your code is slow as it is calculating the gcd using subtraction.

So, apart from reading the number of test cases in the first line, you could try

a) use modulo instead of subtraction
or
b) running it on your local system, then copy/paste the answer into the "Your answer" field

vtivadze     2017-07-16 11:57:15

Thank you Quandray...

Modulo really helped... It was mentioned about modulo in description of the problem but I did not consider that it would be so important... :)

Good luck...

Please login and solve 5 problems to be able to post at forum