Gets the prime function between 100?200, main () {for ($i =100; $i <201; $i + +) {$b = False;for ($j =2; $j < $i-1; $j + +) {$k = $i% $j; if ($k = = 0) {$b = True;//break;}} if (! $b) {echo $i. "
";}}} My doubts at break that place, test the final result, there is no break, are the same result. But if you're going to use a program to explain a mathematical definition, you have to add a break, right?
Reply to discussion (solution)
No break will affect the printed result, because the printing condition is $i prime number
However, for operational efficiency, there is no break when you need to compare all the data ($i-1) before the end, and when there is a break when the first composite is found, then the invalid labor will not have to do
No break will affect the printed result, because the printing condition is $i prime number
However, for operational efficiency, there is no break when you need to compare all the data ($i-1) before the end, and when there is a break when the first composite is found, then the invalid labor will not have to do
+1
When you try to find a prime number within 20000 or greater, you know the difference between break and no break, you might as well test
......
Thanks to xuzuning, I have consolidated a basic knowledge.
/*navicat MySQL Data transfersource server:localhostsource Server version:50532source Host:localho St:3306source database:testtarget Server type:mysqltarget server Version:50532file encoding:65001 date:2014-04-10 16:53:46*/set foreign_key_checks=0;--------------------------------Table structure for ' Guagua_ Config '------------------------------DROP TABLE IF EXISTS ' guagua_config '; CREATE TABLE ' guagua_config ' (' gid ' int (ten) unsigned NOT null auto_increment, ' eid ' int (one) ' NOT null ' 0 ', ' rew ard ' Text COMMENT ' Sets the item, serializes ', ' words ' varchar ($) Default ', ' StopTime ' datetime default NULL, PRIMARY KEY (' gid ')) E Ngine=myisam DEFAULT Charset=utf8 comment= ' scratch-on configuration ';--------------------------------Records of guagua_config-------- ------------------------------------------------------Table structure for ' guagua_order '------------------------- -----DROP TABLE IF EXISTS ' Guagua_order '; CREATE TABLE ' Guagua_order ' (' id ' int (one) unsigned NOT NULL auto_increment, ' eid ' int (one) not null default ' 0 ', ' phone ' int (one) ' NOT null ' default ' 0 ', ' name ' varchar ( Not null default ' ', ' reward ' varchar (TEN) NOT null default ' COMMENT ' Gain Award ', ' time ' datetime NOT NULL, PRIMARY KEY (' ID ')) Engine=innodb DEFAULT Charset=utf8;--------------------------------Records of Guagua_order------------------------ ------