Write a PHP web service factors-xml.php
that computes and outputs prime factorization of integers as XML.
(sample solution)
(solution code)
Provide the following behavior:
factors.php
with an n
parameter outputs the prime factors of that integer.
For example, the request factors.php?n=264
would output:
<integer value="264"> <factor>2</factor> <factor>2</factor> <factor>2</factor> <factor>3</factor> <factor>11</factor> </integer>
One algorithm for prime factorization of n
is to loop through each integer i from 2-n, and for each time n is divisible by i, add i to your list of prime factors.
n
parameter should return an HTTP error code 400 (Invalid Request) with an instructive error message.
Write a PHP web service factors-json.php
that computes and outputs prime factorization of integers as JSON.
(sample solution)
(solution code)
Provide the following behavior:
factors.php
with an n
parameter outputs the prime factors of that integer.
For example, the request factors.php?n=264
would output:
{"value": 264, "factors": [2, 2, 2, 3, 11]}
One algorithm for prime factorization of n
is to loop through each integer i from 2-n, and for each time n is divisible by i, add i to your list of prime factors.
n
parameter should return an HTTP error code 400 (Invalid Request) with an instructive error message.