The question of obtaining prime numbers with a function

Source: Internet
Author: User
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------------------------ ------
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.