search

Home  >  Q&A  >  body text

How to solve this problem

(1) Generate 1000 integers of different multiples of 3 and store them in the file a.txt, one number per line;

(2) Generate 1000 integers of different multiples of 5 and store them in the file b.txt, one number per line;

(3) Please tell me the number of the same numbers in a.txt and b.txt, and list them


饮浮觞 zyq饮浮觞 zyq1875 days ago1280

reply all(1)I'll reply

  • Simine

    Simine2019-11-01 09:58:11

    The flaw is that there is no weight judgment, but the range is given to 1 million, so the probability should be very low

    <?php

    $a = fopen('a.txt', 'w ');

    $b = fopen('b.txt', 'w');


    for($i = 0; $i < 1000; $i ) {

    fwrite($a, getResult(3) . "\r\n");

    fwrite($b, getResult(5) . "\r\n");

    }

    function getResult($num){

    return $num * mt_rand(1, 1000000);

    }

    reply
    0
  • Cancelreply