1 / 3
Oct 2011

I am trying to do this: spoj.pl/problems/GCD/1

import itertools as it
def gcd(a,b):
    if b==0: return a
    return gcd(b,a%b)
s=raw_input()
while s:
    t=int(s)
    ans=0
    for i in set(it.permutations(s)):
        ans=gcd(t,int(''.join(i)))
    print ans
    s=raw_input()

I checked for the itertools module. It is acceptable at SPOJ.
I think maybe the problem lies with ''.join(i), but I am not getting any testcases for it. Any help is appreciated..

  • created

    Oct '11
  • last reply

    Oct '11
  • 2

    replies

  • 397

    views

  • 2

    users

  • 1

    link

True, but the permutations()-function is not implemented in Python 2.5 ... wink

Ahh, right on spot.. blush
I should seriously stop using 2.7 interpreter for Py2.5.. blush
With Py3, its getting TLE, now I need to think some more.. unamused