fork download
  1. #!/usr/bin/perl
  2. # your code goes here
  3. for (<DATA>) {
  4. ($X, $y) = split;
  5. $x = $m = $X % $y;
  6. my ($n, %h);
  7. $h{$x} = 1;
  8. while(1) {
  9. $x = 10 * $x % $y;
  10. $n++;
  11. last if $h{$x};
  12. $h{$x} = 1;
  13. }
  14. print "$X/$y => ", ($x ? $n : $x), "\n";
  15. }
  16. __DATA__
  17. 1234 555
  18.  
Success #stdin #stdout 0s 17496KB
stdin
Standard input is empty
stdout
1234/555 => 4