URAL 1698||UVA 12009 解题报告

题意:

找出平方后的尾数还是本身的n位数有几个

解法:

高精度打表,用java比较方便。

做uva 12009的时候暴力打表找得到的结论是:符合要求的n位数为一个或者两个, 且后最后两个数的后m位都是符合要求的m位数。

又有ural 1698的n的最大值为2000,所以不能暴力打表,要利用以上结论和一个YY的结论:如果之前的50个数都不能推出两个符合要求的n位数,符合要求的m位数只有一个。这样就可以减少非常多的计算量。打表的时候求n+1位符合要求的数的时候只要枚举之前的至多50个数,在第n+1为从1-9枚举,不足的位补0即可。

//uva 12009
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
const int maxn = 100005;
const int inf = 1111111111;
char a[]={"66323172405515756102352543994999345608083801190741530060056055744818709692785099775918050075416428527708162011350246806058163276171676765260937528056844214486193960499834472806721906670417240094234466197812426690787535944616698508064636137166384049029219341881909581659524477861846140912878298438431703248173428886572737663146519104988029447960814673760503957196893714671801375619055462996814764263903953007319108169802938509890062166509580863811000557423423230896109004106619977392256259918212890625"};
char b[]={"33676827594484243897647456005000654391916198809258469939943944255181290307214900224081949924583571472291837988649753193941836723828323234739062471943155785513806039500165527193278093329582759905765533802187573309212464055383301491935363862833615950970780658118090418340475522138153859087121701561568296751826571113427262336853480895011970552039185326239496042803106285328198624380944537003185235736096046992680891830197061490109937833490419136188999442576576769103890995893380022607743740081787109376"};

int main()
{
    //freopen("in.txt","r",stdin);
    string x,y;
    int cas,n;
    scanf("%d",&cas);
    for(int ca = 1; ca<=cas; ca++)
    {
        printf("Case #%d: ",ca);
        scanf("%d",&n);
        if(n==1)
        {
            printf("0 1 5 6\n");
            continue;
        }
        x.assign(a+500-n,a+500);
        y.assign(b+500-n,b+500);
        //x = a[500-n];
        //y = b[500-n];
        if(x[0]==0&&y[0]==0) printf("Impossible\n");
        else if(x[0]=='0') cout<<y<<endl;
        else if(y[0]=='0') cout<<x<<endl;
        else
        {
            if(x>y) cout<<y<<" "<<x<<endl;
            else cout<<x<<" "<<y<<endl;
        }
    }
    return 0;
}



你可能感兴趣的:(URAL 1698||UVA 12009 解题报告)