NO. The problem asks for n such that n = i (mod v[i]). As long as no
v[i] is 0, you will *never* have to reduce anything mod 0 ever.
> also, is it necessary to write efficient code or just brute force is OK?
You will want some level of efficiency. There is a builtin function
called CRT_list in Sage, which you may find useful.
> Best,
> Andrey.
>
>
> 2012/2/16 William Stein <wst...@gmail.com>
>>
>>
>> On Feb 16, 2012 7:26 PM, "Andrey Sarantsev" <ansa...@gmail.com> wrote:
>> >
>> > Dear Prof. Stein,
>> >
>> > what's wrong with this:
>> >
>> > def crt(v):
>> > n = len(v)
>> > for k in range(n):
>> > if (v[k] == 0):
>> > return None
>> > p = prod(v)
>> > if p < 0:
>> > p = -p
>> > def if_crt(v, a):
>> > bulean = True
>> > n = len(v)
>> > for k in range(n)
>> > if (a % k != v[k] % k):
>>
>> k=0 so v[k]%k will never work --- mod 0 is not defined.
>>
>> > bulean = False
>> > return bulean
>> > k = 0
>> > while ((k < p) or if_crt(v, k)):
>> > if (not(if_crt(v, k))):
>> > k = k + 1
>> > if (k == p):
>> > return None
>> > else:
>> > return k
>> >
>> >
>> > crt([3, 4, 5])
>> >
>> > Thanks,
>> > Andrey.
>
>
--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org
For the purposes of the midterm, please just consider 1 to be
composite (so you don't have to raise an error). For
the midterm, you may define composite to mean "not prime".
But yes, I completely agree -- the number 1 is neither prime nor composite.
Thanks,
-- William
>
> Andrey.
>
>
> 2012/2/17 William Stein <wst...@gmail.com>
>>
>> It works perfectly for me. I just copied and pasted your code:
>>
>>
>> {{{id=9|
>> def div(a, b):
>> try:
>> c =float(a/b)
>> except(ZeroDivisionError):
>> return None
>> return c
>>
>>
>> ///
>> }}}
>>
>> {{{id=8|
>> div(2, 0) is None
>> ///
>> True
>> }}}
>>
>> On Fri, Feb 17, 2012 at 10:28 AM, Andrey Sarantsev <ansa...@gmail.com>
>> wrote:
>> > Sir,
>> >
>> > I am trying to model raising an exception:
>> >
>> > def div(a, b):
>> > try:
>> > c =float(a/b)
>> > except(ZeroDivisionError):
>> > return None
>> > return c
>> >
>> >
>> > div(2, 0)
>> >
>> > it does not work!
>> > could you help me?
>> >
>> > Andrey.
>> >
>> > 2012/2/17 William Stein <wst...@gmail.com>