Nyoj 330 a simple mathematical problem

Source: Internet
Author: User
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 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.