UVa 202 Repeating decimals "analog"

Source: Internet
Author: User

Test instructions: Enter integers A and b, output A/b repeating decimal, and the length of the loop section

This article of study

http://blog.csdn.net/mobius_strip/article/details/39870555

Because the remainder of n%m can only be one of 0 to M-1, according to the principle of the drawer, when the calculation of m+1 times there is at least one remainder of the same

Find it difficult to understand the problem.

Then manually drew a 5/7 of the vertical division of the formula, and understand some of the

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <Set>9#include <queue>Ten#include <algorithm> One using namespacestd; A  - #defineforeach (I,c) for (__typeof (C.begin ()) i = C.begin (); I! = C.end (); ++i) -  thetypedefLong LongLL; - Const intINF = (1<< -)-1; - Const intMod=1000000007; - Const intmaxn=100005; +  - intVIS[MAXN],R[MAXN],S[MAXN]; +  A intMain () { at     intn,m; -      while(cin>>n>>m) { -memset (Vis,0,sizeof(Vis)); -Memset (R,0,sizeof(R)); -memset (s),0,sizeof(s)); -          in         intCnt=0; -         intt=N; tor[cnt++]=n/m; +n=n%m; -          while(!vis[n]&&N) { thevis[n]=CNT; *S[cnt]=n;//The s array is stored with the corresponding remainder $r[cnt++]=n*Ten/m;//The r array is stored in the corresponding quotientPanax Notoginsengn=n*Ten%m; -         } the          +printf"%d/%d =%d.", t,m,r[0]); A          the          for(intI=1; i<cnt&i<= -; i++){ +             if(s[i]==n&&n) printf ("("); -printf"%d", R[i]); $         } $         if(!n) printf ("(0");  -         if(CNT > -) printf ("...");  -printf") \ n");  theprintf"%d = number of digits in repeating cycle\n\n",!n?1: cnt-Vis[n]);  -     }Wuyi     return 0; the}
View Code

I'm going to have to draw more pictures----Dizzy--------------.

Writing a simulation is very uncomfortable------------

Goooooooooooooo----------

UVa 202 Repeating decimals "analog"

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.