Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: [Hardest Maths Statement Puzzle] Toughest Math Statement Question |
| Date | 2012-01-31 06:19 -0800 |
| Organization | http://groups.google.com |
| Message-ID | <8610849.1416.1328019561212.JavaMail.geo-discussion-forums@prnc5> (permalink) |
| References | <d2f643df-1028-4906-808d-faa935f94fa0@f8g2000prm.googlegroups.com> <4F090789.D54@mindspring.com> <kfnaa5a2v1l.fsf@x-alumni2.alumni.caltech.edu> <4F233391.5FC@mindspring.com> |
在 2012年1月28日星期六UTC+8上午7时30分25秒,pete写道:
> Tim Rentsch wrote:
> >
> > pete
> writes:
> >
> > > divya bisht wrote:
> > >>
> > >> Toughest Math Statement Question
> > >> (Source : http://hardest-puzzle.blogspot.com/2011/12/toughest-math-statement-question.html
> > >> )
> > >>
> > >> I am thinking of a 6-digit number. The sum of the digits is 43.
> > >>
> > >> And only two of the following three statements about the number are
> > >> true:
> > >>
> > >> (1) it's a square number,
> > >> (2) it's a cube number, and
> > >> (3) the number is under 500000.
> > >
> > > [snip program -- 114 lines of code, 24 lines of comments]
> >
> > Seems like a rather long program for the problem... how
> > about this instead?
> >
> > #include <stdio.h>
> >
> > int digit_sum_of_equals( unsigned number, unsigned total );
> >
> > int
> > main(){
> > const unsigned SUM = 43;
> > unsigned i = 999, j = 99, s, c;
> > /*** 's' is the square of 'i', 'c' is the cube of 'j' ***/
> >
> > printf( "Looking for six digit numbers whose digits total %u...\n", SUM );
> >
> > while( s = i*i, c = j*j*j, s > 99999 || c > 99999 ){
> >
> > if( s > c && s < 500000 && digit_sum_of_equals( s, SUM ) ){
> > printf( " %u == %u**2\n", s, i );
> > }
> >
> > if( c > s && c < 500000 && digit_sum_of_equals( c, SUM ) ){
> > printf( " %u == %3u**3\n", c, j );
> > }
> >
> > if( s == c && s >= 500000 && digit_sum_of_equals( s, SUM ) ){
> > printf( " %u == %u**2 == %u**3\n", s, i, j );
> > }
> >
> > if( s >= c ) i--;
> > if( c >= s ) j--;
> > }
> >
> > return 0;
> > }
> >
> > int
> > digit_sum_of_equals( unsigned n, unsigned t ){
> > return n == 0 ? t == 0 : digit_sum_of_equals( n/10, t - n%10 );
> > }
>
> The algorithm seems to be a little more clever.
> I'll have to study it a bit.
>
> --
> pete
Looking for an integer number rasied to a power of 6 that fits all
conditions in the range should be easy even without writing a program.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: [Hardest Maths Statement Puzzle] Toughest Math Statement Question pete <pfiland@mindspring.com> - 2012-01-07 22:03 -0500
Re: [Hardest Maths Statement Puzzle] Toughest Math Statement Question Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-26 10:11 -0800
Re: [Hardest Maths Statement Puzzle] Toughest Math Statement Question pete <pfiland@mindspring.com> - 2012-01-27 17:06 -0500
Re: [Hardest Maths Statement Puzzle] Toughest Math Statement Question pete <pfiland@mindspring.com> - 2012-01-27 18:30 -0500
Re: [Hardest Maths Statement Puzzle] Toughest Math Statement Question 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-31 06:19 -0800
Re: [Hardest Maths Statement Puzzle] Toughest Math Statement Question Willem <willem@toad.stack.nl> - 2012-03-08 22:26 +0000
Re: [Hardest Maths Statement Puzzle] Toughest Math Statement Question Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-31 22:28 -0800
Re: [Hardest Maths Statement Puzzle] Toughest Math Statement Question pete <pfiland@mindspring.com> - 2012-02-01 18:47 -0500
Re: [Hardest Maths Statement Puzzle] Toughest Math Statement Question Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-08 12:24 -0800
csiph-web