- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图解决欧拉项目 problem 3这是:
13195 的质因数是 5、7、13 和 29。数字 600851475143 的最大质因数是多少?
这是我的解决方案,它适用于较小的值,但不知何故无法完成所需的数量:
public class Pro3 {
public static void main(String[] args) {
long l=600851475143L;
for(long lo=l/2;lo>=2;lo--){
if(l%lo==0 && isPrime(lo)==true){
System.out.println(lo);
break;
}
}
}
static boolean isPrime(long x){
for(int i=2;i<=Math.sqrt(x);i++){
if(x%i==0){
return false;
}
}
return true;
}
}
最佳答案
你可以试试这个方法
public static List<Double> primeFactors(double numbers) {
double n = numbers;
List<Double> factors = new ArrayList<>();
for (int i = 2; i <= n / i; i++) {
while (n % i == 0) {
factors.add((double) i);
n /= i;
}
}
if (n > 1) {
factors.add(n);
}
return factors;
}
public static void main(String[] args) {
List<Double> result=primeFactors(600851475143d);
System.out.println("largest prime factor is :" + result.get(result.size()-1));
}
输出:
largest prime factor is :6857.0
关于java - 最大素因子-欧拉工程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24772139/
假设您有一个在白天接收订单的仓库。这些订单可以是提取产品或向仓库添加产品。在一天结束时,您会得到一份仍包含在仓库中的元素 list 。由于劳动力非常稀少,因此可能会发生订单在仓库的票务系统收到订单的当
有哪些学习音频操作/工程/编程的好资源? 最佳答案 如果您对编写音频效果感兴趣,这两个网站非常好: Music DSP KVR Developer Forum 关于audio - 有哪些学习音频操作/
我的程序写错了 struct vector v; 代替 vector v; 但编译器似乎并不关心:http://codepad.org/TCPb8p2u 为什么有效?使用或不使用 struct 是否存
我创建了一个 Settings自动检索或打印关联 JTextField 上的设置值的类。我的绑定(bind)函数如下所示: public void bindToInput(final String s
下面的例子可以编译,但是输出很奇怪: #include #include struct A { int a; char b; bool c; }; int main() {
如何在Mac-Os上打开已有的Android Studio制作的Flutter工程导出ipa版本的app?可以使用 Mac-Os 版本的 Android Studio 来完成,还是我必须使用 X-Co
我是一名优秀的程序员,十分优秀!