This post has been edited by **AdamSpeight2008**: 26 May 2012 - 04:43 AM

## 36 Replies - 27130 Views - Last Post: 12 June 2012 - 04:36 PM

### #16

## Re: Challenge: how many distinct terms in the sequence

Posted 26 May 2012 - 04:41 AM

### #17

## Re: Challenge: how many distinct terms in the sequence

Posted 26 May 2012 - 12:05 PM

adam, the .size() method is what you want; why is that loop even their?. also "#include "stdafx.h"" and _tmain are non standard. to boot, that's the same solution as before , not a more clever solution

adam:

still; this isn't a very good solution.

This post has been edited by **ishkabible**: 26 May 2012 - 12:35 PM

### #18

## Re: Challenge: how many distinct terms in the sequence

Posted 26 May 2012 - 10:52 PM

### #19

## Re: Challenge: how many distinct terms in the sequence

Posted 26 May 2012 - 11:08 PM

ishkabible, on 26 May 2012 - 02:05 PM, said:

I don't see a neat way around it, but I see a way to deal with it. I'm having a different problem just now, which suggests that my algorithm, though neat, isn't quite correct, and maybe can't be correct. I might have to back up and rethink. I might be coming at it from the wrong end.

### #20

## Re: Challenge: how many distinct terms in the sequence

Posted 26 May 2012 - 11:14 PM

edit:

adam: C++ programers don't use intelisense...also that's showing you an implementation detail that makes perfect sese. std::set is almost always implemented as a self balancing binary tree and so are std::map, and std::multimap. they have an extremely common implementation so creating 1 _Tree class that accepts all the right templates and creating a typedef for each one makes perfect sense

duaaaaa, adam

but ya, that kinda sucks for documentation. I almost always just use my browser for documentation.

edit2:

I wonder how if they use policy based design to get the enriched interfaces that map and multimap provide...I bet that's what that 'false' template argument is for; not really a policy but same idea.

This post has been edited by **ishkabible**: 26 May 2012 - 11:22 PM

### #21

## Re: Challenge: how many distinct terms in the sequence

Posted 26 May 2012 - 11:29 PM

ishkabible, on 27 May 2012 - 01:14 AM, said:

Basically, it's this:

The problem is that this doesn't understand that for example (3^4)^3 == (3^3)^4, and 27 and 81 are both in range, so it's overcounting. So I'm thinking maybe turning it around somehow, but I don't see exactly how yet. Or else I could complicate it, but I want it to be a nice answer.

### #22

## Re: Challenge: how many distinct terms in the sequence

Posted 26 May 2012 - 11:53 PM

edit: also, when I run that code it under counts for me

nvm, I copied it wrong.

This post has been edited by **ishkabible**: 26 May 2012 - 11:57 PM

### #23

## Re: Challenge: how many distinct terms in the sequence

Posted 27 May 2012 - 12:07 AM

### #24

## Re: Challenge: how many distinct terms in the sequence

Posted 27 May 2012 - 12:19 AM

### #25

## Re: Challenge: how many distinct terms in the sequence

Posted 27 May 2012 - 12:21 AM

The reason why I'm surprised is that there definitely are numbers of the form a^b that are only one apart (for example 2^3 = 8 and 3^2 = 9 = 8+1) and there are (lots of numbers) between 2^53 and 100^100 such that using doubles x == x+1 would be true. I don't see why there can't be any numbers greater than 2^53, such that both x = a^b and x+1 = c^d for some a,b,c,d > 1.

This post has been edited by **sepp2k**: 27 May 2012 - 12:22 AM

### #26

## Re: Challenge: how many distinct terms in the sequence

Posted 27 May 2012 - 12:33 AM

Edit:

Quote

Or are you having hard time accepting that some vb.net programmers know their

This post has been edited by **AdamSpeight2008**: 27 May 2012 - 12:38 AM

### #27

## Re: Challenge: how many distinct terms in the sequence

Posted 27 May 2012 - 12:35 AM

2^56 == 4^28 so if by some magic someone can explain how pow(4.0, 28.0) == pow(2.0, 56.0) then you have your answer I'd say

it probably has something to do with how the values are represented; as a base and an exponent so whole numbers to the power of whole numbers work up to much larger values...but I'm not sure.

it all works out somehow; 2^56 == 4^28 == 16^14 == 256 ^ 7

I'm pretty sure whole numbers less than some number K to the power of 1023(maybe like 512, not sure) can be represented perfectly. I think K is greater than 100 by a good bit.

This post has been edited by **ishkabible**: 27 May 2012 - 12:41 AM

### #28

## Re: Challenge: how many distinct terms in the sequence

Posted 27 May 2012 - 12:41 AM

AdamSpeight2008, on 27 May 2012 - 09:33 AM, said:

Both 2^53 and 2^53+1 are whole numbers. However pow(2,53) == pow(2,53) + 1 is true when using IEEE double precision numbers. So clearly whole numbers in the given range are affected by floating point inaccuracy.

Quote

No.

ishkabible, on 27 May 2012 - 09:35 AM, said:

2^56 == 4^28 so if by some magic someone can explain how pow(4.0, 28.0) == pow(2.0, 56.0) then you have your answer I'd say

pow(a,b) == pow(c,d) will always return true if the resulting numbers are really equal. What I'm talking about is a case where the resulting numbers should not be equal, but == still returns true.

Quote

Obviously any powers of 2 can be represented without problem. But for example 2^53+1 will be equal to 2^53 using doubles. So all I'm asking is why aren't there two whole numbers a,b such that a^b = 2^53+1 for example?

This post has been edited by **sepp2k**: 27 May 2012 - 12:43 AM

### #29

## Re: Challenge: how many distinct terms in the sequence

Posted 27 May 2012 - 12:49 AM

ishkabible, on 27 May 2012 - 09:35 AM, said:

Whole numbers up to 2^53 can be represented perfectly. After that every number will at least be equal to either its successor or predecessor.

This post has been edited by **sepp2k**: 27 May 2012 - 12:50 AM

### #30

## Re: Challenge: how many distinct terms in the sequence

Posted 27 May 2012 - 12:49 AM

Quote

whatever proof gave you that answer, I would think allows this to happen. I wasn't aware that that was a true statement but what ever reasoning allows for that gives the answer to your question.

nvm, you want a case where pow(x,y) == pow(c,d) even though it's not true...yes I have no clue.

edit:

I just realized it's 3:00 AM where I am...I need to go to bed night

This post has been edited by **ishkabible**: 27 May 2012 - 12:53 AM