Ultraviolet A 202-repeating decimals

Source: Internet
Author: User

Question: The cycle section for calculating scores.

Analysis: number theory, combination.

The remainder of n divided by m can only be 0 ~ On the basis of the drawer principle, when m + 1 is calculated, at least one remainder is the same,

It is a cyclic section. It stores the remainder and divisor and outputs the result.

Note: (⊙ _ ⊙ ).

#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;int r[3003],u[3003],s[3003];int main(){int n,m,t;while (cin >> n >> m) {t = n;memset(r, 0, sizeof(r));memset(u, 0, sizeof(u));int count = 0;r[count ++] = n/m;n = n%m;while (!u[n] && n) {u[n] = count;s[count] = n;r[count ++] = 10*n/m;n = 10*n%m;}printf("%d/%d = %d",t,m,r[0]);printf(".");for (int i = 1 ; i < count && i <= 50 ; ++ i) {if (n && s[i] == n) printf("(");printf("%d",r[i]);}if (!n) printf("(0");if (count > 50) printf("...");printf(")\n");printf("   %d = number of digits in repeating cycle\n\n",!n?1:count-u[n]);}return 0;}

Ultraviolet A 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.