Php obtains the sum of values less than 89 that can be divided by 1 and itself. I cannot find a clue about this. I want to find a method to instruct php to obtain the number of divisible values of 1 and itself within 89. I cannot find a clue about this.
Reply content:
Php obtains the sum of values less than 89 that can be divided by 1 and itself. I cannot find a clue about this.
I have encountered this problem. I remember it was encountered when I went to a company for an interview. I specially sorted it out. you can refer to it for a good understanding.
Final function getPrimesNumber ($ number) {$ primes = array (); for ($ I = 1; $ I <$ number; $ I ++) {for ($ j = 2; $ j <$ I; $ j ++) {if ($ I % $ j = 0) {continue 2 ;}} $ primes [] = $ I;} return $ primes ;}
YesOnly
The number that can be divided by 1 and itself, that is, the prime number.
$ Max = 89; for ($ I = 1; $ I <= $ max; $ I ++) {$ k = 0; for ($ j = 1; $ j <$ I; $ j ++) {if ($ I % $ j = 0) {$ k ++ ;}} if ($ k = 1) {echo $ I. '\ n ';}}