Created
March 19, 2014 12:35
-
-
Save SiarheiFedartsou/9640762 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Какое значение вернёт вызов функции на языке Java count(32767)? | |
private BigInteger g(BigInteger n, BigInteger g) | |
{ | |
if (g.compareTo(BigInteger.ONE) <= 0 || g.compareTo(n.subtract(BigInteger.ONE)) >= 0){ | |
return BigInteger.ONE; | |
} | |
BigInteger result = BigInteger.ONE; | |
BigInteger c = BigInteger.valueOf(2); | |
while (c.compareTo(g) <= 0){ | |
BigInteger d = n.subtract(g); | |
if (c.compareTo(d) <= 0){ | |
result = result.add(g(d, c)); | |
} | |
c = c.add(BigInteger.ONE); | |
} | |
return result; | |
} | |
public BigInteger count(int n) | |
{ | |
BigInteger v = BigInteger.valueOf(n); | |
BigInteger result = BigInteger.valueOf(1 - v.abs().signum()); | |
BigInteger c = BigInteger.ONE; | |
while (c.compareTo(v) <= 0){ | |
result = result.add(g(v, c)); | |
c = c.add(BigInteger.ONE); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment