UVA-10624 Super Number

Source: Internet
Author: User

The main topic: given two numbers n and M, if the number of length m satisfies for each I (n <= i <= m), the number of the first I bit can be divisible by I, then this number is the super number, to find the smallest dictionary order of the required super-number.

Problem-solving ideas: direct violence on the line, if every time to divide the judgment, the current number of each bit to take the remainder operation, then will time out, so every 18 bits to take the remainder (long Long data range is:-9223372036854775808). 9223372036854775807, so it can be AC at around 1S.

#include <cstdio>intN, M, a[ *];BOOLJudgeintCNT) {Long LongTMP =0; for(inti =0; I < CNT; ++i) {TMP = TMP *Ten+ A[i];if(i = = -) TMP%= CNT; }returntmp% CNT;}BOOLDFS (intcur) {if(cur = = m)return true; for(inti = cur?0:1; I <Ten; ++i) {A[cur] = i;if((Cur < n-1|| !judge (cur +1)) && DFS (cur +1))return true; }return false;}intMain () {intT, cnt =0;scanf("%d", &t); while(t--) {printf("Case%d:", ++cnt);scanf("%d%d", &n, &m);if(DFS (0)) { for(inti =0; I < m; ++i)printf("%d", A[i]);puts(""); }Else            puts("-1"); }return 0;}

UVA-10624 Super Number

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.