SPOJ #2 Prime Generator
My first idea was Sieve of Eratosthenes, too. But obviously my coding was not optimal and it exceeded 6s time limit. Then I googled it. Sounds like Miller-Rabin Testing is a much more serious solution. http://www.cnblogs.com/feature/articles/1824667.html It is based on Fermat Little Theory and property of square root of unity. But the practical use of this method was not satisfactory - it is not 100% accurate - flawness with P of 1/(4^k) - k the MR testing times.
But it is only #2 in SPOJ, it doesn't require too much number theory stuff - it is a matter of prime sieve instead of primality testing, and Sieve of Eratosthenes works - as long you code it in smart way. Check it out here: http://jamie-wong.com/2009/11/12/spoj-problem-2-prime-generator/
SPOJ #2 Prime Generator的更多相关文章
- Spoj PRIME1 - Prime Generator
题意翻译 求给定的两个数之间的素数 Translated by @kaiming 题目描述 Peter wants to generate some prime numbers for his cry ...
- SPOJ PRIME1 - Prime Generator(线性筛)
Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate ...
- 素数筛法--SPOJ Problem 2 Prime Generator
质数(prime number)又称素数,除了1和它本身外,不能整除以其他自然数,换句话说就是该数除了1和它本身以外不再有其他的因数:否则称为合数.最小的质数是2. 要判断一个整数N是不是质数很简单, ...
- spoj Prime Generator
题意:判断ll-rr范围内的质数. 一个个用miller-rabin算法判断 //#pragma comment(linker,"/STACK:1024000000,1024000000&q ...
- Prime Generator
Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate ...
- 【学术篇】SPOJ GEN Text Generator AC自动机+矩阵快速幂
还有5天省选才开始点字符串这棵技能树是不是太晚了点... ~题目の传送门~ AC自动机不想讲了QAQ.其实很久以前是学过然后打过板子的, 但也仅限于打过板子了~ 之前莫名其妙学了一个指针版的但是好像不 ...
- Nth prime & numbers of primes (模板)
都是取的模板,这几天做的素数题挺多的,所以整理了放在这里,感觉有一天回用到的! SPOJ:Nth Prime: 求第N个素数,N<1e9. #include<bits/stdc++ ...
- Java 7 Concurrency Cookbook 翻译 第一章 线程管理之二
三.中断一个线程 一个拥有多个线程的Java程序要结束,需要满足两个条件之一:一是所有的非后台线程都执行结束了:二是某个线程执行了 System.exit() 方法.当你想要终结一个运行中的Java程 ...
- JavaScript 性能优化 --By Google V8 Team Manager
原文:https://developers.google.com/v8/?hl=zh-CN Be Prepared before writing code[9:35] Understand how V ...
随机推荐
- Java程序如何生成Jar、exe及安装文件
http://blog.csdn.net/luoweifu/article/details/7628006/ 一.用Eclipse生产Jar文件 首先,看一下我的项目的目录结构: 1,项目名字上面点右 ...
- UI学习笔记---第十二天UITabBarController
页签视图控制器-UITabBarController 自定义UITabBar block高级 一.UITabBarController 结构为三层:Tab bar controller v ...
- 递归神经网络(RNN)简介(转载)
在此之前,我们已经学习了前馈网络的两种结构--多层感知器和卷积神经网络,这两种结构有一个特点,就是假设输入是一个独立的没有上下文联系的单位,比如输入是一张图片,网络识别是狗还是猫.但是对于一些有明显的 ...
- UVa 11988 破损的键盘(链表)
原题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- Json数据,转换规则,
JSON数据转换,规则是遇见json 中的{},则是数组[],遇见name:value,则是'key'=>'value', 但是不带键值的数组如['xxxxxx'],json_encode后仍然 ...
- jQuery使用伪递归重复执行动画
使用setInterval()来重复执行动画,会因为动画执行过程的时候,setInterval()的时间依然是在走的,所以会导致动画的调用时间不理想,因此只能使用递归来重复执行动画. // 首页LOG ...
- 关于form 上传文件时的小问题
平时的form一般写成这样: <form action=" " method="" id="" name=""&g ...
- Vi个人学习使用心得
找句首/句末 光标所在行:句首: shift+^; 句末: shift +$; 括号匹配:光标在某一括号上,然后shift+% 快速对齐 针对括号的内容:将括号中的内容全部选中之后(按V后, shif ...
- 论文笔记之:From Facial Parts Responses to Face Detection: A Deep Learning Approach
From Facial Parts Responses to Face Detection: A Deep Learning Approach ICCV 2015 从以上两张图就可以感受到本文所提方法 ...
- Agent admitted failure to sign using the key
SSH生成id_rsa, id_rsa.pub后,连接服务器却报: Agent admitted failure to sign using the key 错误. 解决方法: 在当前用户下执行命令: ...