题意就是对于输入的整数n(-1000<=n<=1000),乘以567,然后除以9,然后加7492,结果再乘以235,然后再除以47,最后再减去498,求最后结果的值的十位上的数字是多少。
上述内容经过化简,就是n * 315 + 36962,求解也就很简单了。不过这里python版本还是要注意,对负整数进行整除操作时所获得的结果未必是你想要的,所以还是转化为正整数再做整除操作为好。
python版本代码
testcase = int(input())
while testcase > 0:
n = int(input())
res = (n * 315 + 36962)
if res < 0:
res = -res
i = (res//10) % 10
print(i)
testcase -= 1
C++版本代码
#include <iostream>
#include<cstdio>
using namespace std;
//#define ZANGFONG
int main()
{
#ifdef ZANGFONG
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif // ZANGFONG
int testcase,n,i,j;
scanf("%d\n",&testcase);
while(testcase--)
{
scanf("%d\n",&n);
j = n * 315 + 36962;
i = (j / 10)%10;
printf("%d\n",i>=0?i:-i);
}
return 0;
}