[1, 1008] How many n

Source: Internet
Author: User

Question: http://acm.hit.edu.cn/hoj/problem/view? Id = 1008

Reference: http://hujianliu-tuo.blog.163.com/blog/#m=0&t=1&c=fks_087068085080081075083080083095085086087069086095086069086

This question seems very simple. I tried to test all the numbers one by one. But when I did it, I found that I do not know the value range of K, in addition, if a timeout occurs during the process, you can avoid these problems only after referring to the code linked above. First, if the remainder of a number divided by the divisor can be divisible after the change, then the number can be divisible. Second, if the remainder is not divisible, an infinite loop occurs, so when the Division times reach a certain value, if the division is not completed, it indicates a loop. How big is it? It is also a good choice than yourself. However, it is surprising that some people's Code only ran for a few seconds ~ I can't think of anything in the future. I need to analyze it more. In many cases, it can be solved without violence.

# Include <iostream> using namespace STD; int main () {int n, m; while (CIN> N> m) {int num = N, Count = 1; while (Num % m! = 0) & (count <= 2 * m) {num = 10 * (Num % m) + N; count ++ ;} if (COUNT = 2 * m + 1) Count = 0; cout <count <Endl;} return 0 ;}


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.