C ++ 389 ไบต์
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/miller_rabin.hpp>
using namespace boost::random;typedef boost::multiprecision::cpp_int Z;int main(int,char**v){mt19937 m(clock());independent_bits_engine<mt11213b,256,Z>g(m);Z n{v[1]},p;while(p++<=n)if(miller_rabin_test(p,25,g)&&p.convert_to<std::string>().find( "666" )!=-1)std::cout<<p<<" ";}
นี่เป็นโปรแกรมเต็มรูปแบบ!
คุณจะต้องเพิ่มเพื่อรวบรวม (หรือคัดลอกและวางลงในเชลล์ C ++ ออนไลน์ที่คุณชื่นชอบ)
เรียกใช้จากบรรทัดคำสั่งโดยให้nเป็นอาร์กิวเมนต์
Ungolfed:
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/miller_rabin.hpp>
using namespace boost::random;
typedef boost::multiprecision::cpp_int integer;
int main( int argc, char** argv )
{
mt19937 mt( clock() );
independent_bits_engine <mt11213b, 256, integer> rng( mt );
integer input {argv[ 1 ]};
integer possible;
while (possible++ <= input)
if (
// is_prime( possible )
miller_rabin_test( possible, 25, rng )
&&
// possible has "666" in it
(possible.convert_to <std::string> ().find( "666" ) != std::string::npos))
std::cout << possible << " ";
}
มีการสร้างทางลัดในแง่ของการทดสอบตัวเลขแบบสุ่ม รหัสเดิมเริ่มทดสอบช่วงเวลาที่เป็นไปได้ที่ 6661 และเพิ่มขึ้นสอง คุณจะได้รับคำเตือนคอมไพเลอร์ด้วยเหตุนั้น (-1) ตรงนั้นแทนที่จะเป็น npos
ถึงกระนั้นมันก็ค่อนข้างเร็ว ใช้เวลาประมาณ 40 วินาทีในการค้นหาจำนวนทั้งหมด 214 ครั้งภายใต้ 1,000,000 ครั้งใน AMD Sempron 130 เก่าของฉัน
: D ^
output the nth satan primeท้าทาย ...