I've tried use a program which is will work in sqrt(n),but it got TLE.,please help me
http://acm.pku.edu.cn/JudgeOnline/problem?id=1811

Recommended Answers

All 5 Replies

If you look back in this forum, the prime number problem has been discussed many, many times in just the past week.

What do you mean by "it got TLE"?

"TLE" means time limit error,and that integers could be at most 2^54.So with those big numbers cannot be checked out in one second!!!(Even if you've used sqrt(n)!!!)

"TLE" means time limit error,and that integers could be at most 2^54.So with those big numbers cannot be checked out in one second!!!(Even if you've used sqrt(n)!!!)

I don't think testing a single number of that size presents a time problem. Consider that the square root of 2^54 is 2^27, or about 134 million. On a reasonably modern PC, that is a fairly insignificant task.

Or, are you saying that you have a time limit to meet, and that nothing beyond 2^54 can be done in that time?

The simple, brute force approach we using in teaching examples will, of course, not be the most efficient. There are other algorithms, more complex and mathematically based that you might find and implement.

Yes, I need very effective algoithm. As you said square root of 2^54 is 2^27(about 134million)
and that will be at least one second,but there would be a lot of numbers to be checked.
So what kind of agorithm shall I use?(or where I can find)

Yes, I need very effective algoithm. As you said square root of 2^54 is 2^27(about 134million)
and that will be at least one second,but there would be a lot of numbers to be checked.
So what kind of agorithm shall I use?(or where I can find)

Googling for "fast prime number algorithm" will find some references that may be helpful. Here's one

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.