The method of dividing a large number by a maximum of 202 by using a uva202 division by a large number.

Source: Internet
Author: User
Tags integer division

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;} 


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.