Coj 2024 Wonderland Saga (v)--a genius awakening Prime sieve

Source: Internet
Author: User

Organize the template, while measuring the memset,for,fill who is fast ...

Results: Memset fastest, followed by For,fill slowest qaq ....

1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;Ten Const intmaxn=10000000+Ten; One BOOLPRI[MAXN]; A voidMakepriintN) { -     intLIM=SQRT (n); memset (PRI,true,sizeof(PRI)); -      for(intI=2; i<=lim;i++)if(Pri[i]) for(intJ=i*i;j<=n;j+=i) pri[j]=false;return; the } -InlineintRead () { -     intx=0, sig=1;CharCh=GetChar (); -      while(!isdigit (CH)) {if(ch=='-') sig=-1; ch=GetChar ();} +      while(IsDigit (CH)) x=Ten*x+ch-'0', ch=GetChar (); -     returnx*=Sig; + } AInlinevoidWriteintx) { at     if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; -     intlen=0, buf[ the]; while(x) buf[len++]=x%Ten, x/=Ten; -      for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; - } - intN; - voidinit () { inn=read (); Makepri (n); -      for(intI=2; i<=n;i++)if(Pri[i]) write (i), ENT; to     return; + } - voidWork () { the     return; * } $ voidprint () {Panax Notoginseng     return; - } the intMain () {init (); work ();p rint ();return 0;}

Coj 2024 Wonderland Saga (v)--a genius awakening Prime sieve

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.