{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003emmm is learning division, she\u0027s so proud of herself that she can figure out the sum of all the divisors of numbers no larger than 100 within one day!\u003cbr\u003eBut her teacher said \"What if I ask you to give not only the sum but the square-sums of all the divisors of numbers within hexadecimal number 100?\" mmm get stuck and she\u0027s asking for your help.\u003cbr\u003eAttention, because mmm has misunderstood teacher\u0027s words, you have to solve a problem that is a little bit different.\u003cbr\u003eHere\u0027s the problem, given n, you are to calculate the square sums of the digits of all the divisors of n, under the base m.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"Multiple test cases, each test cases is one line with two integers.\u003cbr\u003en and m.(n, m would be given in 10-based)\u003cbr\u003e1≤n≤10\u003csup\u003e9\u003c/sup\u003e\u003cbr\u003e2≤m≤16\u003cbr\u003eThere are less then 10 test cases.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"Output the answer base m."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e10 2\r\n30 5\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e110\r\n112\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"\u003cbr\u003eUse A, B, C...... for 10, 11, 12......\u003cbr\u003eTest case 1: divisors are 1, 2, 5, 10 which means 1, 10, 101, 1010 under base 2, the square sum of digits is \u003cbr\u003e1^2+ (1^2 + 0^2) + (1^2 + 0^2 + 1^2) + .... \u003d 6 \u003d 110 under base 2."}}]}