2017 eighth annual Blue Bridge Cup C + + Group B provincial race-linear prime number column

Source: Internet
Author: User

标题:等差素数列2,3,5,7,11,13,....是素数序列。类似:7,37,67,97,127,157 这样完全由素数组成的等差数列,叫等差素数数列。上边的数列公差为30,长度为6。2004年,格林与华人陶哲轩合作证明了:存在任意长度的素数等差数列。这是数论领域一项惊人的成果!有这一理论为基础,请你借助手中的计算机,满怀信心地搜索:长度为10的等差素数列,其公差最小值是多少?注意:需要提交的是一个整数,不要填写任何多余的内容和说明文字。


比赛的时候有点混乱,结果连暴力都没暴力出来,后来比赛一结束,就看了一遍就想到了怎么写,,心态决定命运啊_(°:з」∠)_


纯暴力打出素数表,然后挨个遍历知道找到合适的就好

1#include <stdio.h>2 intsu[20000]={0};3 intshai[20000]={1,1,0};4 voidp ()5 {6     intk=0;7      for(intI=0;i<10000; i++)8     {9         if(Shai[i])Ten         { One             Continue; A         } -          for(intj=i;j*i<10000; j + +) -         { theshai[i*j]=1; -         } -su[k++]=i; -     } + } - intSuu () + { A     inti,j,k; at      for(i=0;i<10000; i++) -     { -         intkk=Su[i]; -          for(k=1;k< +; k++) -         { -           in              for(j=1;j<Ten; j + +) -             { to                 if(shai[kk+j*K]) +                 { -                      Break; the                 } *             } $              if(j>=Ten)Panax Notoginseng              { -                  returnK; the              }  +         } A     } the } + intMain () - { $ p (); $     intA=Suu (); -printf"%d\n", a); -     return 0; the}

 

2017 eighth annual Blue Bridge Cup C + + Group B, provincial-linear decimal number column

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.