UVa 256 quirksome Squares: enumeration | | Two times congruence

Source: Internet
Author: User
Tags time limit

256-quirksome Squares

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=192

The number 3025 has a remarkable quirk:if you split it decimal representation in two strings of equal length (25) and square The sum of the numbers so obtained, you obtain the original number:

The problem is to determine all numbers and has a given even number of digits.

For example, 4-digit numbers run from 0000 to 9999. Note that leading zeroes should is taken into account. This means the 0001 which is equal to

is a quirksome number of 4 digits. The number of digits may 2,4,6 or 8. Although Maxint is only 32767 and numbers of eight digits are to asked for, a well-versed programmer can keep he numbers in The range of the integers. However efficiency should be given a thought.

Input

The input of your program is a Textflle containing numbers of digits (taken to 2,4,6,8), each number on a line of it ow N.

Output

The output is a textfile consisting of lines containing the quirksome numbers (ordered according to the input numbers and For each input number in increasing order).

Warning:please Note this number of digits in the output was equal to the number in the corresponding input Line:lead ING zeroes May is suppressed.

Sample Input

2
2

Sample Output

of
81 ba
(a)

You can enumerate directly from the 0~9999, because the right side of the equation must be a full square.

Enumeration method:

/*0.015s*/
    
#include <bits/stdc++.h>  
using namespace std;  
const int MAXN = 5;  
const int DIGIT[MAXN] = {0, m, 1000, 10000};  
    
Vector<int> STORE[MAXN];  
int I, II, J, X;  
    
void init ()  
{for  
    (i = 0; i < 10000; ++i)  
    {  
        II = i * i;  
        for (j = 1; j < 5; ++j)  
        {  
            if (I < digit[j])  
            {  
                X = ii/digit[j] + II% digit[j];  
                if (X = = i) store[j].push_back (ii)  
            ;  
        }  
    
}} int main ()  
{  
    init ();  
    int N, M;  
    while (~SCANF ("%d", &n))  
    {  
        M = N >> 1;  
        for (i = 0; i < store[m].size (); ++i)  
            printf ("%0*d\n", N, Store[m][i));  
    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.