HDU 3195 Interesting Numbers

题目链接 : HDU3195

Interesting Numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 84    Accepted Submission(s): 41


Problem Description
  To play with the numbers is always interesting. Here is just one! Look at the number: 9376. We notice that: 9376 * 9376 = 87909376 with the last four digits the same as the number itself!
  Here comes the problem. What the i-th number of this kinds of the number? Suppose that 0 is the first one.
 


 

Input
There are exactly 26 cases. Process to the end of file
Each case begin with N (1 <= N <= 26) in one line.
 


 

Output
Output the N-th number each in one line. It is promised that the number would be fit the 64-bit integer.
 


 

Sample Input
  
  
1 2 3
 


 

Sample Output
  
  
0 1 5
 


 

Author
ZSTU
 


 

Source
 


 

Recommend
lcy
 

 

一个interesting number应该有如下性质

假设他是一个n位 那么他的后n-1,n-2,n-3,....,1为一定单独也是interesting number

所以就可以通过低位向高位递推  如果找到一个m位的interesting number

那么枚举第m+1位上的数  来找是否存在interesting number

如果不存在就结束。

 

#include<stdio.h>   
#include<string.h>   
#include<stdlib.h>   
#include<algorithm>   
#include<math.h>  
using namespace std;   


long long num[27];
void cal()
{
    int front=1,tail;
    long long wei=1;
    num[0]=0;
    while(1)
    {
        int k=front;
        tail=0;
        for(int i=1;i<10;i++)
        {
            for(int j=0;j<k;j++)
            {
                long long b=num[j]+i*wei,c=0;
                for(long long m=wei;m>0;m/=10)
                {
                    long long d=(b/m-(b/(10*m))*10)*m,e=b%(10*wei/m);
                    c+=(d*e);
                }
                c%=(wei*10);
                if(c==b) 
                {
                    num[front++]=b;
                    if(front>25) return;
                }            
            }
        }
        wei*=10;
    }
}
int main()
{
    cal();
    int n;
    while(scanf("%d",&n)==1)
    {
        printf("%I64d\n",num[n-1]);
    }
    return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值