ICode9

精准搜索请尝试: 精确搜索
  • c – 具有车轮分解的Eratosthenes筛2019-07-28 23:08:36

    我正在实现一个相当快速的素数发生器,我通过对eratosthenes筛子的一些优化获得了一些不错的结果.特别是,在算法的初步部分,我以这种方式跳过所有2和3的倍数: template<class Sieve, class SizeT> void PrimeGenerator<Sieve, SizeT>::factorize() { SizeT c = 2; m_sieve[2

  • 如何在Python中存储计算结果,以便我的程序不会计算两次相同的东西?2019-07-26 02:06:58

    我一直遇到Python中的程序问题(我是一个完整的新手),它不存储计算中的数据,并且当我觉得它应该保存它时反复进行.如何让Python保存答案,以便它不会一遍又一遍地计算程序? 例如: import prime def g(x): i=0 while i<len(prime.sieve(x)): print str(prime.sieve(x)[

  • c – 在不超出时间限制的情况下查找素数2019-07-23 01:06:13

    好的,首先要做的事情.是的,这个问题来自编程竞赛.不,我不是在试图作弊,因为比赛已于4小时前结束.我很确定我的代码是正确的,但比赛的编译器说它给出了错误的答案.我尝试了另一个编译器,它说“超出时间限制”. 那么,首先,请您告诉我代码是否正确? [一个编译器说它不是] 如果是,那么我

  • C如何在不使用排序的情况下从大小为n的数组中打印最小数字2019-07-23 01:05:01

    我要WAP打印最小的&没有排序的给定大小数组的最大素数.我已经编写了最大数字的代码,但是对于最小的数字,它没有运行,因为我将素数的值与初始化为0的min进行比较,但是如果我将If_else分成两部分 >包含c == 2检查 >包含[i] 然后它运行因为然后在c == 2,min已经从数组中提供了一个值,

  • U - Primes2019-07-21 17:02:44

    这道题真的良心签到题: 直接判断素数就OK了 注意题上指定2 不是素数哦 #include<map> #include<list> #include<ctime> #include<queue> #include<deque> #include<cmath> #include<stack> #include<string> #include<cstdlib> #include<cstri

  • LeetCode -- 204. Count Primes2019-07-19 11:00:07

      题目标签 HashTab(哈希表)   题意及思路 题意:略 思路:有关素数的题目我所知道有两种做法。一种是最基本的isPrime算法,关键点在循环判断时,上限为Math.sqrt(n) (求n是否为素数)。另外一种做法是,求某段区间内的素数个数,一般比赛中,n一般很大,这时候一般会采用素数表(Table),素数表的求法是,

  • 0x31 prime distance(质数)2019-07-18 10:57:25

    题目描述: 给定两个整数L和U,你需要在闭区间[L,U]内找到距离最接近的两个相邻质数C1和C2(即C2-C1是最小的),如果存在相同距离的其他相邻质数对,则输出第一对。 同时,你还需要找到距离最远的两个相邻质数D1和D2(即D1-D2是最大的),如果存在相同距离的其他相邻质数对,则输出第一对。 输入格式:

  • PAT甲级——A1015 Reversible Primes2019-07-15 23:03:23

    A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime. Now given any two positive integers N (&

  • 素数检查Python2019-07-15 17:58:11

    我写了这个非常简单的素数检查: prime = int(input()) if prime % prime == 0 and prime % 2 != 0 and prime % 3 != 0 or prime == 2 or prime == 3: print("true") else: print("false") …似乎以某种方式工作,但我不确定它是否正确的方式,有人可以确认吗?解决方法: i’

  • java – 查找600851475143中最大的素数?2019-07-15 15:01:55

    我试图从http://projecteuler.net解决问题3.但是,当我运行程序时,没有打印出来. 我究竟做错了什么?问题:600851475143的最大主要因素是什么? public class project_3 { public boolean prime(long x) // if x is prime return true { boolean bool = false;

  • python – 素数代码的优化2019-07-14 23:55:53

    这是我在python中的代码,用于计算小于给定数字的素数之和. 我还能做些什么来优化它? import math primes = [2,] #primes store the prime numbers for i in xrange(3,20000,2): #i is the test number x = math.sqrt(i) ispri

  • python – 在Fibonacci序列中输出素数2019-07-13 04:05:10

    有人可以检查我的代码.我在循环中提取素数时遇到问题.如果用户输入5,则输出应为:2 3 5 13 89,如果用户输入7,则输出应为2 3 5 13 89 233 1597等, countPrime= int(0) endNum= int(0) a0= int(0) a1= int(1) checkPrime= False valueN= int(input("Enter the value of N: \n")

  • python – Lucas-Lehmer素性测试的快速按位模数2019-07-10 03:55:13

    Lucas-Lehmer primality test测试素数以确定它们是否也是Mersenne primes.其中一个瓶颈是计算(s ** 2 – 2)%(2 ** p – 1)时的模数运算. 使用按位运算可以大大加快速度(参见L-L链接),这是迄今为止最好的: def mod(n,p): """ Returns the value of (s**2 - 2) % (2**p -1)""

  • LeetCode313. Super Ugly Number2019-07-09 09:35:22

    Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. Example: Input: n = 12, primes = [2,7,13,19] Output: 32 Explanation: [1,2,4,7,8,13,14,16

  • Python 3.2数论库2019-07-09 05:56:02

    我找不到一个可用的python 3数论库.我找到的所有库都是为python版本2编写的,或者它们缺少我正在寻找的功能.我需要模块化的平方根函数,它可以处理具有已知分解的复合数. 我可以自己滚动,但我认为其他人已经解决了这个问题,这是一个相对常规的事情.解决方法:这个函数集合具有模块化

  • javascript – 查找小于输入的所有素数2019-07-08 18:36:01

    我有一个输入字段来取最大数字并找到所有较小的素数. 它应该返回一个数组并显示带有警报的数组. 除了我每次都变得空白. HTML: <p>Please enter the maximum number you'd like to find all prime numbers below it for.</p> <p><input type="text" id="number" /></p> <

  • code forces 1176 D. Recover it!2019-07-07 17:01:18

    原题链接:https://codeforces.com/contest/1176/problem/D 本文链接:https://www.cnblogs.com/blowhail/p/11146761.html 题目大意是 两个个数列 a , b 相同 ,如果 ai 是素数,那么b数列里添加上第ai个素数(2为第一个),如果不是素数,那么b数列里添加上ai的最大因子。现在给出添加完之后的b数

  • python – 素数生成拼图(边缘情况)2019-07-01 22:45:38

    我正在编码网站上解决以下问题.对于测试中的一些边缘情况(隐藏测试),它失败了,但我不确定它们是什么.有人看到任何问题吗? 问题:设A是一个按顺序压在一起的所有素数的串(即235711131719 ……).给定索引n,返回5位数的字符串,其中第一个数字位于A中的索引n处. 例如foo(0)=> 23571和foo(

  • c# – 如何生成用户定义的素数?2019-06-27 02:54:07

    我正在尝试根据用户输入生成素数.这是我到目前为止,但我似乎无法弄清楚: Console.Write("Please enter the number of prime numbers you would like to see:"); int numberOfPrimes = Convert.ToInt32(Console.ReadLine()); for (int x = 0; x < numberOfPrimes; x++) { for

  • python – 为什么这个算法更糟?2019-06-26 18:44:07

    在Wikipedia中,这是生成素数的给定算法之一: def eratosthenes_sieve(n): # Create a candidate list within which non-primes will be # marked as None; only candidates below sqrt(n) need be checked. candidates = [i for i in range(n + 1)] fin = int(n

  • Python素数生成器产量vs返回2019-06-25 01:44:38

    参见英文答案 > Fastest way to list all primes below N                                    30个 搜索python素数生成器,我发现: def primes(n): if n==2: return [2] elif n<2: return [] s=range(3,n+1,2) mroot = n **

  • 如何加快寻找过程的速度?2019-06-23 09:46:48

    当我遇到问题时,我在项目Euler上做了问题7.我的代码需要很长时间才能完成.这是我的代码. def Problem7(): num = 0 p = 0 while p < 10002 : prime = True for i in range(2,num): if (num%i==0): prime = False

  • python – 加速字符串拆分和连接2019-06-10 11:42:28

    我正在努力解决Project Euler’s problem #35 The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. How many circular primes are there below one million? 这是我的解决方案: import numpy as np

  • java – 为什么我们在获得素数因子时不必检查数字是否为素数?2019-06-08 20:48:52

    这是寻找素因子的典型代码: public static List<Integer> primeFactors(int numbers) { int n = numbers; List<Integer> factors = new ArrayList<Integer>(); for (int i = 2; i <= n / i; i++) { while (n % i == 0) { factors.add(i)

  • leetcode 313. 超级丑数(Super Ugly Number)2019-05-31 09:48:04

    目录 题目描述: 示例: 解法: 题目描述: 编写一段程序来查找第 n 个超级丑数。 超级丑数是指其所有质因数都是长度为 k 的质数列表 primes 中的正整数。 示例: 输入: n = 12, primes = [2,7,13,19] 输出: 32 解释: 给定长度为 4 的质数列表 primes = [2,7,13,19],前 12 个超级丑

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有