IIntel·DSASDE-1Onsite – Coding 1
Check if a Number Is Prime / Integer Square Root
Problem
Write the most efficient routine to test primality and to compute integer square root without floating point.
Example
isPrime(97) -> true; isqrt(50) -> 7
Constraints
- n up to 10^12
Approach
Trial division up to √n for primality; binary search or Newton's method for isqrt. Discuss overflow.
added 6 days ago