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)