The method of dividing a large number by a maximum of 202 by using a uva202 division by a large number.
Background: vodwa: forget that there is a blank line between each answer! 2_WA: no space is displayed on both sides of the equal sign !!!!!!!!
Idea: Separate integers and decimals. integer division is used directly. fractional part: Numerator = (numerator % denominator) * 10. in addition, each molecule is stored in str [0]. When an existing molecule appears, the fractional part starts to loop!
Learning:
1. Nest pigeon principle (Drawer principle, Dirichlet principle ):
Simple Description: if there are n cages where n + 1 pigeons reside, at least one cage contains two pigeons.
General description (Describe using Gaussian Functions): Divides n elements into m sets. At least one set contains more than or equal to [(n-1)/m] + 1.
For this question, a % B has a maximum of B-1, according to the nest pigeon principle, the number of cycles is less than or equal to the B-1.
#include<stdio.h>int str[2][10000]; int main(void){ int a,b,intger; while(scanf("%d %d",&a,&b)!=EOF){ int count=0,start,aa=a; intger=a/b; a=a%b; while(1){ a*=10; for(int i=0;i < count;i++){ if(a==str[0][i]){ start=i; goto l1; } } str[0][count]=a; str[1][count++]=a/b; a=a%b; }l1: printf("%d/%d = %d.",aa,b,intger); for(int i=0;i < start;i++){ printf("%d",str[1][i]); } if(count<=50){ printf("("); for(int i=start;i < count;i++){ printf("%d",str[1][i]); } printf(")\n"); }else{ printf("("); for(int i=start;i < start+50;i++){ printf("%d",str[1][i]); } printf("...)\n"); } printf(" %d = number of digits in repeating cycle\n\n",count-start); } return 0;}