Problem Regarding Queue

Discussion in 'Python' started by mukesh tiwari, Feb 9, 2010.

  1. Could some one please tell what is wrong with this code. I am trying
    to use Queue in this program but i am getting error
    Traceback (most recent call last):
    File "/home/user/NetBeansProjects/NewPythonProject2/src/
    Pollard_rho.py", line 80, in <module>
    factor(n)
    File "/home/user/NetBeansProjects/NewPythonProject2/src/
    Pollard_rho.py", line 59, in factor
    Q_1=Queue()
    NameError: global name 'Queue' is not defined.
    As i am new to python so kindly pardon me if i sound stupid.
    Here is the code
    # To change this template, choose Tools | Templates
    # and open the template in the editor.

    __author__="Mukesh Tiwari"
    __date__ ="$Feb 10, 2010 1:35:26 AM$"

    import random
    import sys
    def gcd(a,b):
    while b:
    a,b=b,a%b
    return a

    def rabin_miller(p):
    if(p<2):
    return False
    if(p!=2 and p%2==0):
    return False
    s=p-1
    while(s%2==0):
    s>>=1
    for i in xrange(10):
    a=random.randrange(p-1)+1
    temp=s
    mod=pow(a,temp,p)
    while(temp!=p-1 and mod!=1 and mod!=p-1):
    mod=(mod*mod)%p
    temp=temp*2
    if(mod!=p-1 and temp%2==0):
    return False
    return True

    def pollard(n):
    if(n%2==0):
    return 2;
    x=random.randrange(2,1000000)
    c=random.randrange(2,1000000)
    y=x
    d=1
    while(d==1):
    x=(x*x+c)%n
    y=(y*y+c)%n
    y=(y*y+c)%n
    d=gcd(x-y,n)
    if(d==n):
    break;
    return d;
    def factor(n):
    #if(rabin_miller(n)):
    # print n
    # return
    #d=pollard(n)
    #if(d!=n):
    # factor(d)
    # factor(n/d)
    #else:
    # factor(n)

    Q_1=Queue()
    Q_2=Queue()
    Q_1.put(n)
    while(not Q_1.empty()):
    l=Q_1.get()
    if(rabin_miller(l)):
    Q_2.put(l)
    continue
    d=pollard(l)
    if(d==l):Q_1.put(l)
    else:
    Q_1.put(d)
    Q_1.put(l/d)
    while(not Q_2.empty()):
    print Q_2.get()



    if __name__ == "__main__":
    while(True):
    n=input();
    factor(n)
     
    mukesh tiwari, Feb 9, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul L. Du Bois

    Queue.Queue-like class without the busy-wait

    Paul L. Du Bois, Mar 24, 2005, in forum: Python
    Replies:
    29
    Views:
    1,109
    Antoon Pardon
    Apr 4, 2005
  2. Russell Warren

    Is Queue.Queue.queue.clear() thread-safe?

    Russell Warren, Jun 22, 2006, in forum: Python
    Replies:
    4
    Views:
    720
    Russell Warren
    Jun 27, 2006
  3. Kceiw
    Replies:
    3
    Views:
    1,043
    Jim Langston
    Mar 14, 2006
  4. Gabriel Rossetti
    Replies:
    3
    Views:
    594
    Jerry Hill
    Apr 25, 2008
  5. Kris
    Replies:
    0
    Views:
    531
Loading...

Share This Page