UVa 474

From Algorithmist
Jump to navigation Jump to search

Problem Number - Problem Name[edit]

Summary[edit]

  • the problem is that find out the 2^-n value and print it correct format. that's all.

Explanation[edit]

we have a function printf(). where we can print 2^-n but its format x.xxx e-XXX. so we have to follow another way to solve this problem.

Gotchas[edit]

  • Main logic output highest value is 5.000e-1. because 2^-1 is highest value within range
  • So we know, the number of digit 2^-n. i.e digit = floor (log (2^n)+1) = floor[ nlog2+1). Digit is the power of (e-).
  • Now we have to find the portion 5.000 , we know ½ =0.5 , digit = floor[ 2log2+1] = 1 , so r = ½ *102
  • r = 2^-n*10^digit
  • log(r) = -nlog(2)+digit*log(10)
  • log(r) = -nlog2 + digit*log(5)+digit*log(2)
  • log(r) = (digit-n)log(2)+digit*log(5)
  • r = exp((digit-n)*log(2) +digit*log(5)).
  • Printf( 2^n = r e- digit);
  • ok

Notes[edit]

  • This problem is very easy.

Problem for test case n = 6.

Output should be 2^-6 = 1.563e-2

While judge consider 2^-6 = 1.562e-2.

Implementations[edit]

Grate implementation on Exponential Calculation.


Input[edit]

Sample Input 

1
100
10000
1000000

Output[edit]

2^-1 = 5.000e-1
2^-100 = 7.889e-31
2^-10000 = 5.012e-3011
2^-1000000 = 1.010e-301030

Discussed by[edit]

 Rizoan Tiufiq

Categories here, use the form [[Category:UVa Online Judge|474]] [[Category: Category Name]], see Categories for a list