Math problems.
I understand for a long time is actually to solve a quadratic equation x * (x-1)/2 = y. If y = 0. It indicates that the number is exactly the same.
If not, take X as the first digit and then Y-N and then % 9.
But remember that when % 9 = 0 is 9. 0 is not displayed.
# Include <cstdio> # include <cstring> # include <string> # include <queue> # include <algorithm> # include <map> # include <stack> # include <iostream> # include <list> # include <set> # include <cmath> # define INF 0x7fffffff # define EPS 1e-6 # define ll long longusing namespace STD; int main () {// freopen ("in.txt", "r", stdin); // freopen ("2.txt"," W ", stdout); int T; scanf ("% d", & T); While (t --) {ll n, m; scanf ("% LLD", & N ); int x = int (SQRT (1.0 + 8.0 * n)-1)/2); int y = int (n-x * (x + 1)/2 ); if (y = 0) // n * (n + 1)/2 {If (INT (x) % 9 = 0) printf ("9 \ n"); else printf ("% d \ n", INT (x) % 9 );} else // between {If (Y % 9 = 0) printf ("9 \ n"); else printf ("% d \ n ", Y % 9 );}}}
HDU 1597 find the nth Digit