2013 the fourth annual Blue Bridge Cup A-C + + undergraduate Class A group row it squared (2 numbers multiplied by the large number, the large number of marks of the method)

Source: Internet
Author: User

Xiao Ming is looking at the number 203879 in a daze.


Originally, 203879 * 203879 = 41566646641


What's so magical about that? Carefully observed, 203879 is a 6-digit number, and its number on each digit is different, and it does not appear on all digits after the square to make its own number.


There is a 6-digit number with this feature, please find it!


Let's summarize the screening requirements:
1.6-bit positive integer
2. The numbers on each digit are different
3. Each digit of its square number does not contain any constituent digits of the original number


The answer is a 6-bit positive integer.


Please submit your answer via the browser.
Note: Submit only the other 16 digits that have been given in the question.

Note: Do not write anything else (e.g., descriptive text).

Idea: I*i, the range is 12 digits, more than the range of int, so to record its number of bits, there is a thought is to simulate the multiplication of the operation, with one of the number from the low to high order multiplied by another number, the specific storage please see my ok1 function

AC Code:

#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int flag[10];int num[6]; bool OK (int n) {    int cnt=0;    while (n)    {        if (flag[n%10])            return false;        num[cnt++]=n%10;        flag[n%10]++;        n/=10;    }    return true;} BOOL Ok1 (int n) {    int t=0,j;    for (int j=0;j<6;j++)    {        t+=num[j]*n;        if (Flag[t%10]) return false;        t/=10;    }    while (t)    {        if (flag[t%10])            return false;        t/=10;    }    return true;} int main () {for    (int i=123456;i<=987654;i++)    {        memset (flag,0,sizeof (flag));        if (!ok (i))            continue;        else        {            if (Ok1 (i))            {                printf ("%d\n", i);    }}} return 0;}


2013 the fourth session of the Blue Bridge Cup A-C + + undergraduate Class A group row it squared (2 numbers multiplied by a large number, large number of markers)

Related Article

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.