26 lines
542 B
C#
26 lines
542 B
C#
namespace Prac7Meow
|
|
{
|
|
internal class Utils
|
|
{
|
|
public static int NearPow(int n)
|
|
{
|
|
if (n == 0) return 0;
|
|
if (n <= 2) return 2;
|
|
|
|
uint val = (uint)n;
|
|
|
|
val--;
|
|
val |= val >> 1;
|
|
val |= val >> 2;
|
|
val |= val >> 4;
|
|
val |= val >> 8;
|
|
val |= val >> 16;
|
|
val++;
|
|
|
|
if (val == 0) throw new OverflowException("Requested capacity is too large for int.");
|
|
|
|
return (int)val;
|
|
}
|
|
}
|
|
}
|