UVa 202 Repeating decimals

Source: Internet
Author: User
Tags repetition

calculate the repeating decimal cycle section

Enter integers A and B (0<=a<=3000,1<=b<=3000), output A/b repeating decimal representation, and the length of the loop section.

For example, a=5,b=43, decimal notation is 0. (116279069767441860465), and the loop byte length is 21

You can use arrays to store numbers and simulate vertical division to solve them.

The AC code is attached:

1#include <iostream>2#include <cstring>3 using namespacestd;4 5 Const intmax=3050;6 7 intR[max],u[max],s[max];8 9 intMain () {Ten     intn,m,t; One      while(cin>>n>>m) { At=N; -Memset (R,0,sizeof(R)); -memset (U,0,sizeof(U)); thememset (s,-1,sizeof(s)); -         intans=0; -r[ans++]=n/m;//r arrays are used to store numbers -n=n%m; +          while(!u[n]&&n) {//Simulate Vertical Division -U[n]=ans;//The u Array records the location of the repetition point (accession number) +S[ans]=n;//s used to judge at which point the repetition Ar[ans++]=Ten*n/m; atn=Ten*n%m; -         } -cout<<t<<"/"<<m<<" "<<"="<<" "<<r[0]<<"."; -          for(intI=1; i<ans&&i<= -; i++){ -             if(n&&s[i]==n)//start the loop when the condition is established -cout<<"("; incout<<R[i]; -         } to         if(!n)//can be removed at the best +cout<<"(0"; -         if(ans> -)//don't forget to use more than 50 bits ... thecout<<"..."; *cout<<")"<<Endl; $         intSum=n? (Ans-u[n]):1;//Total number of digits minus the number of bits that start the loop is the number of loop bitsPanax Notoginsengcout<<"   "<<sum<<"= number of digits in repeating cycle"<<endl<<Endl; -     } the     return 0; +}

UVa 202 Repeating decimals

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.