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"