[UVA][建表] 974 - Kaprekar Numbers@Morris' Blog|PChome Online 人新台
2012-10-12 20:34:59| 人1,130| 回0 | 上一篇 | 下一篇

[UVA][建表] 974 - Kaprekar Numbers

0 收藏 0 0 站台

Problem C - Kaprekar Numbers

Shri Dattathreya Ramachandra Kaprekar was an Indian mathematician, whose name is associated with a number of concepts in number theory. He was born in Dahanu, near Mumbai, in India. Even as a small child, he was already interested in numbers.

Among his numerous contributions are the so called Kaprekar numbers. These are non-negative integer numbers such that the representation of their square can be split into two parts that add up to the original number again. For example, 55 is a Kaprekar number, because 552 = 3025, which can be split into 30 and 25, and 30 + 25 = 55. There is one special rule: both parts of this sum must be positive. This means that, for example, 10 is not a Kaprekar number, even when 10^2 = 100 and 10+0=10 (but the second part of the sum is zero - not positive).

The Problem

Given a range of numbers, your task is to discover and print all Kaprekar numbers within that range.

Input

The first line of input contains a single number N, representing the number of test cases that follow (1 ≤ N ≤ 1000).

Than follow exactly N lines (one for each test case), each one containing two positive integers separated by a single space: INF and SUP (2 ≤ INF ≤ SUP &le 40000), indicating that the range to consider is the number interval [INF,SUP] (this means that the limits are included in the interval to consider).

Output

For each test case you should start by printing a line in the format case #NUM where NUM is the test case number (starting in one).

Then, you must print all the Kaprekar numbers that appear in the respective range, in ascending order, one per line. If there are no Kaprekar numbers in the specified interval, you should print no kaprekar numbers.

There should also be a blank line between test cases.

See the sample output for an example.

Example Input

3 2 90 30 35 50 55 

Example Output

case #1 9 45 55 case #2 no kaprekar numbers case #3 55 

2006 Programming Contest of Porto University
Round 3, 11th of October of 2006
 
(Author: Pedro Ribeiro - DCC/FCUP)




#include <stdio.h>

int main() {
    int i, j, x, y, tmp;
    char buf[30];
    int ans[50], at = 0;
    for(i = 4; i <= 40000; i++) {
        j = i*i;
        sprintf(buf, "%d", j);
        for(j = 0; buf[j+1]; j++) {
            tmp = buf[j+1];
            buf[j+1] = '\0';
            sscanf(buf, "%d", &x);
            buf[j+1] = tmp;
            sscanf(buf+j+1, "%d", &y);
            if(x && y && x+y == i) {
                ans[at++] = i;
                break;
            }
        }
    }
    int cases = 0;
    scanf("%d", &tmp);
    while(tmp--) {
        scanf("%d %d", &x, &y);
        printf("case #%d\n", ++cases);
        for(i = 0, j = 0; i < at; i++)
            if(ans[i] >= x && ans[i] <= y)
                printf("%d\n", ans[i]), j = 1;
        if(!j)
            puts("no kaprekar numbers");
        if(tmp) puts("");
    }
    return 0;
}

台: Morris
人(1,130) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 不分 | 人分: UVA |
此分下一篇:[UVA][] 10680 - LCM
此分上一篇:[UVA][spfa] 10278 - Fire Station

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86