<p>I’m fairly certain that AP Comp Sci questions won’t be structured this way. When I took the exam, the questions were more practical and object-oriented, rather than some random mathematical function.
Specifically, your solution, though technically “correct,” is not answering what the question is testing. AP exam questions have essentially one “best” answer that they are trying to lead you toward, but any variation up to a reasonable degree will probably be accepted. Your “creative” solution would not likely be accepted, as the question tells you to use modulus division to get the right answer (not to mention that your solution is rather inefficient). Note that on the AP exam, you will use pencil and paper, and your code will be scored by humans, not by machines. Your answer misses the point, so it would not likely earn many points.
See [AP</a> Central - The AP Computer Science A Exam](<a href=“Supporting Students from Day One to Exam Day – AP Central | College Board”>AP Computer Science A Exam – AP Central | College Board) for some released sample FRQs more in line with what the CollegeBoard is testing.</p>