A simple mathematical problem time limit: 3000 MS | memory limit: 65535 kb difficulty: 3
-
Description
-
ZYC recently fell in love with mathematics. One day, DJ came up with a math question to help him. Calculate 1/N, but ZYC cannot answer the question at one time. I hope everyone can help him with programming.
-
Input
-
The integer T in the first line indicates the number of test groups. Followed by T rows, each row has an integer N (1 <=| n |<= 10 ^ 5 ).
-
Output
-
Output 1/n. (It is a circular decimal number and only outputs the first circular section ).
-
Sample Input
-
4237168
-
Sample output
-
0.50.30.1428570.005952380
Directly simulate the method of finding the remainder, use an array record operator, and the other array record whether the remainder has exists. If yes, it indicates that it is the start of the second loop, and jump out of the loop here.
# Include <cstdio> # include <cstring> const int maxn = 100005; int A [maxn], vis [maxn]; int main () {int N, T, I; scanf ("% d", & T); While (t --) {memset (VIS, 0, sizeof (VIS); scanf ("% d", & N ); if (n <0) {printf ("-"); n =-N;} If (n = 1) printf ("1 \ n "); else {int S = 1, num = 0; vis [s] = 1; while (1) {S * = 10; A [num ++] = S/N; S % = N; If (vis [s] | S = 0) break; // returns the remainder or the remainder is 0 (division is allowed) vis [s] = 1;} printf ("0. "); for (I = 0; I <num; I ++) printf (" % d ", a [I]); printf (" \ n ");}} return 0 ;}