UVa 202 large number of divisions

Source: Internet
Author: User
Tags integer division

Background: 1_wa: Forget that there is a blank line between each answer! 2_wa: I don't see a space on either side of the equals sign!!!!!!!!

Idea: integers and decimals are separated, integers are divided directly by integer division, fractional part: numerator = (numerator% denominator) *10. and storing each molecule in str[0], the fractional part begins to circulate when there are molecules that have already appeared!

Learn:

1. Pigeon principle (drawer principle, Dirichlet principle):

Simple description: If there are n cages, n+1 only pigeons live, then at least one cage has two pigeons.

A generalized description ( described with a Gaussian function ): Divide n elements into M-sets, at least one set of elements greater than or equal to [(n-1)/m]+1.

For the subject, a%b up to b-1 a case, according to the principle of nest pigeons, the number of links is less than equal to 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);  }  


UVa 202 large number of divisions

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.