2016 "Baidu Star"-Preliminary (Astar round2a) 1001 All X (HDU5690)--Find the Circulation section | Fast power

Source: Internet
Author: User

A new number consisting of M x numbers, asking if the MoD K equals C.

First to provide a way of thinking, to find the link. Because each time more than one number is carried out (t*10+x) mod K (here is the embodiment of the same comodule), because x,k are determined, as long as T again get the same answer must be the same. So in step-by-step, once a previous number appears, it is clear that the loop will begin. Find this cycle section and put m in the loop (there is a problem here, see 2nd below).

But here are two places to note, the first is that only the current number of occurrences can guarantee the next occurrence of the same number, and does not mean that the current number is the same as the number of it, so the first number does not necessarily participate in the loop. As A simple example, this series of numbers is, 3,4,5,6,4,5,6,4,5,6 ... The first 3 does not participate in a loop. In fact, a score, its denominator and molecules, so it is equivalent to continue to do the same operation, and finally will be in the loop state (does not loop as long as the 0 loop), but it is clear that the first decimal place is not necessarily the part of the loop.

2nd, based on the previous point, m if the smaller is not necessarily in the circular section, then there is no way to put it in the Loop section, then directly from 1 to M can be counted.

The following gives the code of the seniors, very clever to solve all the problems:

1#include <cstdio>2#include <cstring>3#include <iostream>4 using namespacestd;5typedefLong LongLL;6 Const intN =10000+5;7 LL Pos[n];8 LL x, M, K, C;9 intMain () {Ten     intT; One     intCAS =1; Ascanf"%d", &T); -      while(T--){ -memset (POS,-1,sizeof(POS)); thescanf"%i64d%i64d%i64d%i64d", &x, &m, &k, &c); -printf"Case #%d:\n", CAS + +); -         intTMP =0; - LL D; +          for(LL i =1; I <= m; i + +){ -TMP = TMP *Ten+x; +TMP%=K; A             if(Pos[tmp] = =-1){ atPOS[TMP] =i; -}Else{ -D = i-pos[tmp]; -i + = (m-i)/d *D; -                 if(i > m) i-=D; -                  for(LL j = i+1; J <= M; J + +){ inTMP = TMP *Ten+x; -TMP%=K; to                 } +                  Break; -             } the         } *         if(TMP = = c) puts ("Yes"); $         ElsePuts"No");Panax Notoginseng     } -}

The second method is a quick power, very ingenious, directly to move someone else's blog: http://www.cnblogs.com/inmoonlight/p/5515538.html directly without a few lines of code on it, is also very bad.

2016 "Baidu Star"-Preliminary (Astar round2a) 1001 All X (HDU5690)--Find the Circulation section | Fast power

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.