您的位置:首页 > 其它

SGU 107 987654321 problem(打表)

2016-04-14 10:17 337 查看
Description

给出一整数n,问n位的数字中平方后最后九位是987654321的数有多少个

Input

一个整数n表示数字位数(1<=n<=10^6)

Output

n位且平方后最后九位是987654321的数的个数

Sample Input

8

Sample Output

0

Solution

由用例可知八位数没有满足条件的数字,故只需要考虑九位数中满足条件的数有多少即可,这个直接打个表可知一共有8个,故如果n<=8输出0,n=9输出8,n>9输出72,后面输出n-10个0(数字第一位不能为0,除后九位是满足调价的8个数之外其余都可以从0取到10)

Code

#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
//ll mod=1000000000ll;
//for(ll i=1;i<=1e9;i++)
//  if(i*i%mod==987654321ll)
//      printf("%lld\n",i);
//111111111
//119357639
//380642361
//388888889
//611111111
//619357639
//880642361
//888888889
int n;
while(~scanf("%d",&n))
{
if(n<=8)printf("0\n");
else if(n==9)printf("8\n");
else
{
printf("72");
for(int i=0;i<n-10;i++)printf("0");
printf("\n");
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: