[解题报告]256 - Quirksome Squares

本文探讨了具有特定性质的数字,即将其等分为两部分并平方和后能得到原数的数字。通过程序实现,本文提供了针对不同位数数字的求解方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 Quirksome Squares 

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

 

displaymath26

 

The problem is to determine all numbers with this property having a given even number of digits.

 

For example, 4-digit numbers run from 0000 to 9999. Note that leading zeroes should be taken into account. This means that 0001 which is equal to tex2html_wrap_inline28 is a quirksome number of 4 digits. The number of digits may be 2,4,6 or 8. Although maxint is only 32767 and numbers of eight digits are asked for, a well-versed programmer can keep his 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 from 2,4,6,8), each number on a line of its own.

 

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 that the number of digits in the output is equal to the number in the corresponding input line : leading zeroes may not be suppressed.

 

Sample Input

 

2
2

 

Sample Output

 

00
01
81
00
01
81



略水
#include<stdio.h>
int main()
{
    int n;
    int i,j;
    while(scanf("%d",&n)!=EOF)
    {
        if(n==2)
        {
            for(i=0;i<10;i++)
                for(j=0;j<10;j++)
                {
                    if(i+j>=10) break;
                    if ((i+j)*(i+j)==(i*10+j)) printf("%02d\n",i*10+j);
                }
        }
        if(n==4)
        {
            for(i=0;i<100;i++)
                for (j=0;j<100;j++)
                {
                    if(i+j>=100) break;
                    if((i+j)*(i+j)==(i*100+j)) printf("%04d\n",i*100+j);
                }
        }

        if(n==6)
        {
            for(i=0;i<1000;i++)
                for(j=0;j<1000;j++)
                 {
                    if(i+j>=1000) break;
                    if((i+j)*(i+j)==(i*1000+j)) printf("%06d\n",i*1000+j);
                }
        }

        if(n==8)
        {
            for(i=0;i<10000;i++)
                for(j=0;j<10000;j++)
                {
                    if(i+j>=10000) break;
                    if((i+j)*(i+j)==(i*10000+j)) printf("%08d\n",i*10000+j);
                }
        }
    }
    return 0;
}

 

 

转载于:https://www.cnblogs.com/TheLaughingMan/archive/2013/02/25/2927595.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值