集训队作业解题报告_第1页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、题目来源Ural 1586 Threeprime Numberhttp:/acm.timus.ru/problem.aspx?space=1&num=1586问题描述 输出有多少n位整数,其中任意连续三位数字都组成三位数的素数(不首0)。答案模1000000009输出。核心算法 先枚举所有三位质数。递推ai,j,k前i位满足条件,末两位j,k,的方案数。递推方程:ai,j,k=。算法证明 无需证明。算法实现 没有实现上的困难。源代码const pp=1000000009;var p:array1.1000of boolean; a,b:array1.1000of longint; i,j,n,

2、k,ans:longint;function prime(x:longint):boolean;var i:longint;begin for i:=2 to round(sqrt(x)+1) do if x mod i=0 then exit(false); prime:=true;end;begin for i:=101 to 997 do pi:=prime(i); for i:=100 to 997 do if pi then ai:=1 else ai:=0; readln(n); for j:=4 to n do begin fillchar(b,sizeof(b),0); for

3、 i:=101 to 997 do if pi then begin k:=(i mod 100)*10; if pk+1 then bk+1:=(bk+1+ai)mod pp; if pk+3 then bk+3:=(bk+3+ai)mod pp; if pk+7 then bk+7:=(bk+7+ai)mod pp; if pk+9 then bk+9:=(bk+9+ai)mod pp; end; a:=b; end; ans:=0; for i:=101 to 997 do ans:=(ans+ai)mod pp; writeln(ans);end.原题描述:1586. Threepri

4、me NumbersTime Limit: 1.0 secondMemory Limit: 64 MBRest at the sea is wonderful! However, programmer Pasha became awfully bored of lying on a beach in Turkey; so bored that he decided to count the quantity of three-digit prime numbers. This turned out to be so interesting that he then started to stu

5、dy threeprime numbers. Pasha calls an integer a threeprime number if any three consecutive digits of this integer form a three-digit prime number. Pasha had already started working on the theory of the divine origin of such numbers when some vandals poured water on Pasha and cried some incomprehensi

6、ble words like “Sonnenstich!”, “Colpo di sole!”, and “Coup de soleil!” You are to continue Pashas work and find out how often (or rare) threeprime numbers are. InputThe input contains an integer n (3 n 10000). OutputOutput the quantity of n-digit threeprime numbers calculated modulo 109 + 9. Sampleinputoutput4204Problem Author: Denis M

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论