[UVA][大] 10433 - Automorphic Numbers@Morris' Blog|PChome Online 人新台
| | PChome| jQuery.ajax({ url: "https://apis.pchome.com.tw/tools/api/index.php/getEventdata/mypaper/event", type: "GET", dataType:"json" }) .done(function (data) { if (!jQuery.isEmptyObject(data)) { jQuery("#menu_eventURL").attr("href", data.url); jQuery("#menu_eventURL").text(data.name) } else{ console.log('getEventdata is empty'); } }) .fail(function (jqXHR, textStatus) { console.log('getEventdata fail'); }); 登入
2013-05-03 22:28:20| 人1,110| 回0 | 上一篇 | 下一篇

[UVA][大] 10433 - Automophic Numbers

0 收藏 0 0 站台

Brightness of Brain Contest
Problem E
Time limit: 1 second Memory: 32 MB

Automorphic Numbers

The Problem

Recreational mathematics is mathematics that is fun and used as either as a diversion from serious mathematics or as a way of making serious mathematics understandable or palatable.  These are the pedagogic uses of recreational mathematics.  They are already present in the oldest known mathematics and continue to the present day. One of the topic of the recreational mathematics is the Automorphic numbers  which have many use in different  fields.

Automorphic numbers are those numbers whose square ends with the number itself:

52 = 25,
252 = 625,
762 = 5776.

The first automorphic numbers are 1, 5, 6, 25, 76,  ... By definition 0 is not an Automorphic Number and for this particular problem we will not consider 1 as an Automorphic Number.

Automorphic numbers have enormous application in mathematics. In this problem you are to determine whether a given number is Automorphic or not.

The Input

Each line containing a arbitrarily big integer. Some Automorphic number have leading zeros. So leading zeros must be considered as significant. Input is terminated by end of file.

The Output

If the input is an Automorphic number print ``Automorphic number of n-digit.'', where n is the number of digit of the integer which will not be greater then 2000. Otherwise print ``Not an Automorphic number.''.

Sample Input

5 76 34 

Sample Output

Automorphic number of 1-digit. Automorphic number of 2-digit. Not an Automorphic number. 

Suman Mahbub
Created: 01-09-2002
Updated: 14-12-2002

做法:
有要要理,特是 0 1 不算是 Automaorphic Numbers
同, 0001, 000001 .... 也都不是,就因了好多次。

有很多加速的地方,就如只有一些特的尾是可行解,特判一下,
就可以在算上比好理。


#include <stdio.h>
#include <string.h>char in[5000];
int main() {
    int i, j, k;
    while(scanf("%s", in) == 1) {
        if(!strcmp(in, "0") || !strcmp(in, "1")) {
            puts("Not an Automorphic number.");
            continue;
        }
        int x[3005] = {}, y[3005] = {};
        int len = strlen(in);
        for(i = 0, j = len-1; i < len; i++, j--)
            x[j] = in[i]-'0';
        int top = len-1;
        while(top >= 0 && x[top] == 0)
            top--;
        if(top < 0 || (top == 0 && x[top] == 1)) {
            puts("Not an Automorphic number.");
            continue;
        }
        int error = 0;
        for(i = 0; i < len && !error; i++) {
            if(x[i])
                for(j = 0; i+j < len; j++)
                    y[i+j] += x[i]*x[j];
            y[i+1] += y[i]/10;
            y[i] %= 10;
            if(y[i] != x[i])
                error = 1;
        }
        if(error)
            puts("Not an Automorphic number.");
        else
            printf("Automorphic number of %d-digit.\n", len);
    }
    return 0;
}

台: Morris
人(1,110) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 不分 | 人分: UVA |
此分下一篇:[UVA][角排序] 1432 - Fire-Control System
此分上一篇:[UVA][性、二分] 12064 - Count the Points Inside

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能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