我目前正在解决一个数学问题,其中我需要计算减少的适当分数的数量,分子和分母都超过1000000(10 ^ 6).
我有适用于小数字的代码; 给出的示例(值= 8)给出正确的(给定的)答案21.
但是由于我不知道的原因,这个代码似乎对大数字来说非常慢.我在SO上阅读了大量类似的问题,但找不到任何有用的东西.我仔细研究了这个和这个,但这并没有真正帮助我.我的代码以可接受的速度运行,直到1000,然后它变得超级超慢.
import math
def is_prime(n):
if n == 2:
return True
if n % 2 == 0 or n <= 1:
return False
sqr = int(math.sqrt(n)) + 1
for divisor in range(3, sqr, 2):
if n % divisor == 0:
return False
return True
def get_divisors(n):
liste = [1]
if n % 2 == 0:
liste.append(2)
for divisor in range(3, n+1):
if n % divisor == 0:
liste.append(divisor)
return liste …Run Code Online (Sandbox Code Playgroud) 在python 3.1问世时,我有一些旧的程序.在程序中我经常使用它Callable()传递一个函数,它的参数就像我的TKinter应用程序:
tvf.mi(datei_bu, text=datei_opt, command=Callable(exec_datei_opts, datei_opt))
Run Code Online (Sandbox Code Playgroud)
现在我想再次使用我的程序,但是callable- 对象已经消失了.在网络上,我发现在python 3.2中删除了这个功能,没有一个替代方案适合我.
最后我决定重新安装python 3.1.但是,我不知道是否可以同时安装多个python 3版本,或者当我想使用这个特殊版本时如何为这个版本"创建"一个shell命令.
我的问题是:
Callable- 被删除的对象?我目前正在进入 Spigot Pugin 开发并需要访问 GameProfile,因为我需要它作为插件(用于更改皮肤的东西)。我正在使用 Eclipse。
现在,我已经观看了大量使用 GameProfile 的教程,所有这些教程都只是为了
import com.mojang.authlib.GameProfile;
Run Code Online (Sandbox Code Playgroud)
或者
import net.minecraft.util.SOMETHINGLONG.GameProfile
Run Code Online (Sandbox Code Playgroud)
无需解释为什么这条线是可能的。
这是一个和我有同样问题的人,使用第二个命令,但显然可以用第一个命令解决它,所以我试图让这个命令运行。https://www.spigotmc.org/threads/how-to-import-net-minecraft-util.252371/。
如果我尝试包含这样的内容,我会看到com.google.common,com.oracle但是com.suncom.mojang 却无处可见。我发现它必须对您添加到项目中的 .jar 文件执行某些操作,但我不知道如何将 com.mojang... 放入可导入文件中。
当使用 Eclipse 和 Maven 构建一个包含一些用于不和谐机器人的简单 lambda 的项目时,就会发生这种情况。
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.330 s
[INFO] Finished at: 2020-10-04T15:14:13+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project XXX: Compilation failure: Compilation failure:
[ERROR] /C:/XXX/listener/TextMessageListener.java:[24,54] lambda expressions are not supported in -source 7
[ERROR] (use -source 8 or higher to enable lambda expressions)
[ERROR] /C:/XXX/Main.java:[27,30] lambda expressions are not supported in -source 7
[ERROR] (use -source 8 or higher to enable lambda expressions)
[ERROR] /C:/XXX/Main.java:[33,38] method …Run Code Online (Sandbox Code Playgroud) 两者之间有什么区别吗?
if (firstCheck())
return;
if (secondCheck())
return;
Run Code Online (Sandbox Code Playgroud)
和
if (firstCheck() || secondCheck())
return;
Run Code Online (Sandbox Code Playgroud)
?
我的问题的重点是运行时!
java ×2
python ×2
algorithm ×1
c++ ×1
if-statement ×1
maven ×1
minecraft ×1
performance ×1
python-3.1 ×1