# Longest cycle section

Source: Internet
Author: User

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1035

Because the result is either a finite number or an infinite loop of decimals, just simulate the process and then judge the loop to jump out and record the number of loops.

`1#include <iostream>2#include <string.h>3#include <stdio.h>4#include <map>5 using namespacestd;6 intvis[1001],a[1001];7 intMain ()8 {9     //freopen ("A.txt", "R", stdin);Ten     intx,y,z,k; One      for(intI=1; i<= +; i++) A     { -memset (Vis,0,sizeof(Vis)); -x=1, z=0, k=1; the          while(1) -         { -y=x%i; -x=x/i; +             if(y==0|| Vis[y]) Break; -vis[y]=1; +x= (k-x*i) *Ten; Ak=x; atz++; -             //printf ("%d\n", x); -         } -         if(Vis[y]) a[i]=Z; -         Elsea[i]=0; -        //printf ("%d\n", A[i]); in     } -     intn,j=1, ans=0; toscanf"%d",&n); +      for(intI=1; i<=n;i++) -     { the         if(a[i]>ans) *         { \$ans=A[i];Panax Notoginsengj=i; -         } the     } +printf"%d\n", j); A     return 0; the}`

Longest cycle section

Related Keywords:

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.