# Thread: php wrong equation infinity result

1. Member
Join Date
Nov 2012
Posts
3

## php wrong equation infinity result

the equation is

@N means N^N + N^(N+1) + N^(N+2) + ... + N^(N+9)

Find the sum of digits in @321

so i made a little program that first calculate @N

PHP Code:
``` \$n = 321; \$res = 0; for(\$i=0;\$i<10;\$i++){ \$res = \$res + bcpow(\$n,\$n+\$i); } echo \$res;  ```
i get INF !!!
so why the result is infinity ?

2. MCIW-D MCP MCAD MCSD .Net
Join Date
Jul 2007
Location
Wisconsin
Posts
468
Your results are overflowing.

321^100 = 4.472015e+250

that's 250 zeros, and im only raising it to the 100th power. You want to raise it to the 321st power?

9^321 = 2.050433e+306

That's as big as Google's calculator will go...

3. My guess is you're simply generating numbers too large for PHP to handle? 321^321 = 321 * 321 * 321 * 321...[317 more times!], and just 321^4 = 10,617,447,681.

4. Member
Join Date
Nov 2012
Posts
3

## thank you for answers

at first i thought there is something with memory exhausted !

and when i trying to just add two parts like [ N^N + N^(N+1) ] it also give INF !!!

but this equation has a solution and now how to solve this equation ??

this equation is here

http://tournament.arabnet.me/challenge/

in web developer challenge

5. It might simply be that you need to use bc*() functions for all arithmetic operations, not just the bcpow(). Otherwise you'll be exceeding the max PHP integer size (32 or 64 bit unsigned integer).
PHP Code:
``` \$n = 321; \$res = 0; for(\$i=0;\$i<10;\$i++){   \$res = bcadd(\$res, bcpow(\$n, bcadd(\$n, \$i))); } echo \$res;  ```

6. Member
Join Date
Nov 2012
Posts
3
Thank you very much

it's working fine and i got a result

#### Thread Information

##### Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•