Difference between revisions of "2017 AMC 12A Problems/Problem 7"
Thomas0115 (talk | contribs) (→See Also) |
|||
Line 7: | Line 7: | ||
This is a recursive function, which means the function is used to evaluate itself. To solve this, we must identify the base case, <math>f(1)=2</math>. We also know that when <math>n</math> is odd, <math>f(n)=f(n-2)+2</math>. Thus we know that <math>f(2017)=f(2015)+2</math>. Thus we know that n will always be odd in the recursion of <math>f(2017)</math>, and we add two each recursive cycle, which there are <math>1008</math> of. Thus the answer is <math>1008*2+2=2018</math>. | This is a recursive function, which means the function is used to evaluate itself. To solve this, we must identify the base case, <math>f(1)=2</math>. We also know that when <math>n</math> is odd, <math>f(n)=f(n-2)+2</math>. Thus we know that <math>f(2017)=f(2015)+2</math>. Thus we know that n will always be odd in the recursion of <math>f(2017)</math>, and we add two each recursive cycle, which there are <math>1008</math> of. Thus the answer is <math>1008*2+2=2018</math>. | ||
<math>\boxed{\textbf{(B)}}</math> | <math>\boxed{\textbf{(B)}}</math> | ||
+ | |||
+ | Alternatively, simply download java and run this program: | ||
+ | public class Amc12a7 | ||
+ | { | ||
+ | public static int f(int n){ | ||
+ | if(n == 1) | ||
+ | return 2; | ||
+ | else if(n % 2 == 0) | ||
+ | return f(n-1) + 2; | ||
+ | else | ||
+ | return f(n-2) + 2; | ||
+ | } | ||
+ | } | ||
==See Also== | ==See Also== | ||
{{AMC12 box|year=2017|ab=A|num-b=6|num-a=8}} | {{AMC12 box|year=2017|ab=A|num-b=6|num-a=8}} | ||
− |
Revision as of 11:34, 9 February 2017
Problem
Define a function on the positive integers recursively by , if is even, and if is odd and greater than . What is ?
Solution
This is a recursive function, which means the function is used to evaluate itself. To solve this, we must identify the base case, . We also know that when is odd, . Thus we know that . Thus we know that n will always be odd in the recursion of , and we add two each recursive cycle, which there are of. Thus the answer is .
Alternatively, simply download java and run this program: public class Amc12a7 {
public static int f(int n){ if(n == 1) return 2; else if(n % 2 == 0) return f(n-1) + 2; else return f(n-2) + 2; }
}
See Also
2017 AMC 12A (Problems • Answer Key • Resources) | |
Preceded by Problem 6 |
Followed by Problem 8 |
1 • 2 • 3 • 4 • 5 • 6 • 7 • 8 • 9 • 10 • 11 • 12 • 13 • 14 • 15 • 16 • 17 • 18 • 19 • 20 • 21 • 22 • 23 • 24 • 25 | |
All AMC 12 Problems and Solutions |