Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #305

Re: Mystery program...

From "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com>
Newsgroups comp.programming
Subject Re: Mystery program...
Date 2011-05-12 04:14 +0200
Organization A noiseless patient Spider
Message-ID <iqff99$8ut$1@dont-email.me> (permalink)
References <ipkl8k$m5n$1@dont-email.me> <05f7402c-cf0d-4af2-b9a3-eef50af58041@y31g2000vbp.googlegroups.com> <4dc24b67$0$18239$4fafbaef@reader2.news.tin.it> <4dc411fe$0$38650$4fafbaef@reader1.news.tin.it>

Show all headers | View raw


* io_x, on 06.05.2011 17:22:
> "io_x"<a@b.c.invalid>  ha scritto nel messaggio
> news:4dc24b67$0$18239$4fafbaef@reader2.news.tin.it...
>> ;;
>>     at the start
>>     if n=3  b=3-2=1  1<2 esci
>>     this means that if input in range int_min..3 return "n=" +n
>>     not count the overflow for int_min etc
>>
>>    if(n<=3)                  return print("n=" +n)
>>    else if((n-2)%2==0)       return print("m=" +2)
>>    else if((n-2-4)<3)        return print("n=" +n)
>>    else if((n-2-4)%3==0)     return print("m=" +2)
>>    else if((n-2-4-6)<4)      return print("n=" +n)
>>    else if((n-2-4-6)%4==0)   return print("m=" +4)
>>    else if((n-2-4-6-8)<5)    return print("n=" +n)
>>    else if((n-2-4-6-8)%5==0) return print("m=" +5)
>>    ...
>> ;;
>
> and because Sum_i[0..n] i = n(n+1)/2
> it is equivalent to
> n=input()
> for(m=2; m*(m-1)<=n ; ++m)
>     if(n%m==0) {print("m=" m); return;}
> print("n=" n);
> return;
> or
> n=input()
> for(m=2; m<=sqrt(n) ; ++m)
>     if(n%m==0) {print("m=" m); return;}
> print("n=" n);
> return;
>
> so print n if n is<=3 or prime; print m!=n if n%m==0

Thanks to both of you, Paul and io_x.

Cheers,

- Alf


-- 
blog at <url: http://alfps.wordpress.com>

Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Mystery program... "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-05-02 00:10 +0200
  Re: Mystery program... Paul N <gw7rib@aol.com> - 2011-05-04 13:23 -0700
    Re: Mystery program... "io_x" <a@b.c.invalid> - 2011-05-05 09:02 +0200
      Re: Mystery program... "io_x" <a@b.c.invalid> - 2011-05-06 17:22 +0200
        Re: Mystery program... "io_x" <a@b.c.invalid> - 2011-05-07 09:12 +0200
        Re: Mystery program... "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-05-12 04:14 +0200
  Re: Mystery program... tm <thomas.mertes@gmx.at> - 2011-05-11 23:42 -0700
    Re: Mystery program... "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-05-12 14:17 +0200

csiph-web