# php wrong equation infinity result

• 11-08-2012, 02:24 PM
mohamed86medo
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 ?
• 11-08-2012, 03:47 PM
OctoberWind

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...
• 11-08-2012, 03:59 PM
NogDog
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.
• 11-08-2012, 05:32 PM
mohamed86medo
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
• 11-09-2012, 10:23 AM
NogDog
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;  ```
• 11-09-2012, 12:45 PM
mohamed86medo
Thank you very much :)

it's working fine and i got a result

## X vBulletin 4.2.2 Debug Information

• Page Generation 0.10155 seconds
• Memory Usage 2,362KB
• Queries Executed 11 (?)
Template Usage (20):
• (2)bbcode_php_printable
• (1)footer
• (1)gobutton
• (1)navbar_moderation
• (1)navbar_noticebit
• (2)option
• (1)spacer_close
• (1)spacer_open

Phrase Groups Available (3):
• global
• postbit
Included Files (19):
• ./global.php
• ./includes/class_bootstrap.php
• ./includes/init.php
• ./includes/class_core.php
• ./includes/config.php
• ./includes/functions.php
• ./includes/class_friendly_url.php
• ./includes/class_hook.php
• ./includes/class_bootstrap_framework.php
• ./vb/vb.php
• ./vb/phrase.php
• ./includes/functions_calendar.php
• ./includes/class_bbcode_alt.php
• ./includes/class_bbcode.php
• ./includes/functions_bigthree.php
• ./includes/functions_notice.php

Hooks Called (41):
• init_startup
• init_startup_session_setup_start
• database_pre_fetch_array
• database_post_fetch_array
• init_startup_session_setup_complete
• global_bootstrap_init_start
• global_bootstrap_init_complete
• cache_permissions
• fetch_foruminfo
• global_state_check
• global_bootstrap_complete
• global_start
• style_fetch
• global_setup_complete
• bbcode_fetch_tags
• bbcode_create
• bbcode_parse_start
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates