Process
Not really any tricks to this problem. I used a long long to be on the safe side, but I don’t think it’s actually needed after some quick checks on my calculator. To get the digit in the tens column of a number, you can divide by 10 and use mod 10.
For example, to get the tens digit of 257:
257 / 10 = 25
25 % 10 = 5.
/* * Sai Cheemalapati * UVa 11547: Automatic answer * */ #include<cmath> #include<cstdio> using namespace std; long long t, n; int main() { scanf("%lld", &t); while(t--) { scanf("%lld", &n); n *= 567; n /= 9; n += 7492; n *= 235; n /= 47; n -= 498; n /= 10; printf("%d\n", (int) abs(n % 10)); } }
4 637 -120 9999 -9999
1 3 4 2