Problem 3 : Largest prime factor

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Ruger008/article/details/79981148

Problem 3


Largest prime factor

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?


最大质因数

13195的所有质因数为5、7、13和29。

600851475143最大的质因数是多少?


题目解答

    朴素解法:暴力枚举(枚举所有因子并判断是否为素数即可)

       优化算法:

            在这里我们可以利用 算术基本定理 来解决这个问题。

            算术基本定理:任何一个大于1的自然数 N,如果N不为质数,那么N可以唯一分解成有限个质数的乘积。

               遇到的素数不断分解即可,直到分解到1时退出,我们的数字是从小到大遍历的,所以最后分解到一时的素因子一定时最大的。

  题目代码

#include <stdio.h>
#include <inttypes.h>
#define N 600851475143
int main(){
    int32_t ans;
    int64_t temp = N;
    for (int32_t i=2;;i++){
        if (temp % i == 0){
            while (temp % i == 0){
                temp /= i;
            }
            ans = i;
            if(temp == 1){
                break;
            }
        }
    }
    printf("%" PRId32 "\n",ans);
}

                

阅读更多

Largest prime number ever is found

12-03

http://www.newscientist.com/news/news.jsp?id=ns99994438rnrnLargest prime number ever is found rn rn rn15:11 02 December 03 rn rnNewScientist.com news service rn rnA 26-year-old graduate student in the US has made mathematical history by discovering the largest known prime number.rnrnThe new number is 6,320,430 digits long. It took just over two years to find using a distributed network of more than 200,000 computers.rnrnMichael Shafer a chemical engineering student at Michigan State University used his office computer to contribute spare processing power to the Great Internet Mersenne Prime Search (GIMPS). The project has more than 60,000 volunteers from all over the world taking part.rnrn"I had just finished a meeting with my advisor when I saw the computer had found the new prime," Shafer says. "After a short victory dance, I called up my wife and friends involved with GIMPS to share the great news." rnrnPrime numbers are positive integers that can only be divided by themselves and one. Mersenne primes are an especially rare type of prime that take the form 2 p-1, where p is also a prime number. The new number can be represented as 220,996,011-1. It is only the 40th Mersenne prime to have ever been found.rnrnrnBuilding blocks rnrnrnMersenne primes were first discussed by Euclid in 350 BC and have been central to the branch of mathematics known as number theory ever since. They are named after a 17th century French monk who first came up with an important conjecture about which values of p would yield a prime.rnrnPrimes are the building blocks of all positive numbers. They have practical uses too, for example by providing a way of exchanging the cryptographic keys that keep internet communications secure from eavesdropping. However, despite their significance, mathematicians do not understand the way prime numbers are distributed making it very difficult to identify new primes.rnrnMarcus du Sautoy, a mathematician at Oxford University and author of The Music of the Primes, says the discovery is unlikely to add much to our understanding of the way primes are distributed but is still significant. rnrn"It's a really good measure of what our computational capabilities are," he told New Scientist. "It's a really fun project. Everyone gets a different bit of the number universe to look at. It's a bit like the lottery."rnrn The World's No.1 Science & Technology News Service rn rn rn rnLargest prime number ever is found rn rn rn15:11 02 December 03 rn rnNewScientist.com news service rn rnA 26-year-old graduate student in the US has made mathematical history by discovering the largest known prime number.rnrnThe new number is 6,320,430 digits long. It took just over two years to find using a distributed network of more than 200,000 computers.rnrnMichael Shafer a chemical engineering student at Michigan State University used his office computer to contribute spare processing power to the Great Internet Mersenne Prime Search (GIMPS). The project has more than 60,000 volunteers from all over the world taking part.rnrn"I had just finished a meeting with my advisor when I saw the computer had found the new prime," Shafer says. "After a short victory dance, I called up my wife and friends involved with GIMPS to share the great news." rnrnPrime numbers are positive integers that can only be divided by themselves and one. Mersenne primes are an especially rare type of prime that take the form 2 p-1, where p is also a prime number. The new number can be represented as 220,996,011-1. It is only the 40th Mersenne prime to have ever been found.rnrnrnBuilding blocks rnrnrnMersenne primes were first discussed by Euclid in 350 BC and have been central to the branch of mathematics known as number theory ever since. They are named after a 17th century French monk who first came up with an important conjecture about which values of p would yield a prime.rnrnPrimes are the building blocks of all positive numbers. They have practical uses too, for example by providing a way of exchanging the cryptographic keys that keep internet communications secure from eavesdropping. However, despite their significance, mathematicians do not understand the way prime numbers are distributed making it very difficult to identify new primes.rnrnMarcus du Sautoy, a mathematician at Oxford University and author of The Music of the Primes, says the discovery is unlikely to add much to our understanding of the way primes are distributed but is still significant. rnrn"It's a really good measure of what our computational capabilities are," he told New Scientist. "It's a really fun project. Everyone gets a different bit of the number universe to look at. It's a bit like the lottery."rnrnMathematical curiosity rn rnThe GIMPS project uses a central computer server and free software to coordinate the activity of all its contributors. Contributing machines are each allocated different prime number candidates to test.rnrnSome people contribute to GIMPS out of mathematical curiosity or to test their computer hardware, while others just hope to go down in history as the discoverer of a massive prime. There is also a financial incentive with the Electronic Frontier Foundation, a non-profit US group, offering a $100,000 prize for the discovery of the first prime with 10 million digits.rnrnShafer's discovery was made on 17 November but it was not independently verified until now. "It's humbling to see so many people of varied lands, ages and vocations volunteering for this fun and amazing project," says Scott Kurowski, whose company Entropia manages the GIMPS server. rnrn"There are more primes out there," adds George Woltman, who started the GIMPS project in 1996. "And anyone with an internet-connected computer can participate."rn rn rnWill Knightrnrn

没有更多推荐了,返回首页