Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

如果n是素数,岂不非常慢?

Posted by dynamic at 2004-08-30 18:48:16 on Problem 1811
In Reply To:我是这样搞地~~ Posted by:achilles at 2004-08-30 17:35:48
> llong is_prime(llong n)
> {
>     llong old = n;
>     if (n%2 == 0)
>         return 2;
>         
>     llong limit = llong(sqrt(n*1.0)) + 1;
>     if (limit%2 == 0)   --limit;
> 
>     do{
>         if (n%limit == 0)
>         {
>             n = limit;
>             limit = llong(sqrt(n*1.0))+1;
>             if (limit%2 == 0) --limit;
>         }
>         else
>             limit -= 2;
>     }while (limit >= 3);
>     if (old == n)
>         return 1;
>     else
>         return n;
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator