博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SGU107-987654321 problem
阅读量:4504 次
发布时间:2019-06-08

本文共 1352 字,大约阅读时间需要 4 分钟。

今天又是硕果仅存的一题o(╯□╰)o

time limit per test: 0.5 sec.  memory limit per test: 4096 KB

 

For given number N you must output amount of N-digit numbers, such, that last digits of their square is equal to 987654321.

 

Input

Input contains integer number N (1<=N<=106)

 

Output

Write answer to the output.

 

Sample Input

8

Sample Output

0

 题意:输入一个数字N,问你存在多少个平方后最后9位为“987654321”的N位数。

思路:1<=N<=106,显然直接暴力枚举是不可能的,可想到某个数的平方后的低位只与原数的低位有关(如:11^2=121,111^111=12321,211^2=4521),故只要找到符合条件平方后低位出现987654321的最低位数即可。可先写个方程找出符合条件的数,即可知道当位数为9存在8个低位为987654321的数。故当N<9时输出0,当N=9时输出8,当N=10时输出8*9=72,当N>10时,每增加1就多输出一个0(如:N=11,输出720)。

1 #include
2 #include
3 #include
4 #include
5 using namespace std; 6 /*#define inf 1000000000 7 int main() 8 { 9 int n=987654321,flag=0;10 for(long long i=10000000;i<=1000000000;i++)11 {12 long long t=i*inf+n,m=sqrt(t);//printf("%lld\n",t);13 if(m*m==t){printf("%lld %lld\n",m,t);flag=1;}14 }15 if(!flag)printf("qunima");16 }*/17 int main()18 {19 int n;20 cin>>n;21 long long res=9;22 if(n<9)cout<<'0';23 else if(n==9)cout<<'8';24 else25 {26 cout<<"72";27 for(int i=2; i<=n-9; i++)cout<<'0';28 }29 cout<
View Code

 

 

转载于:https://www.cnblogs.com/code-farmer-cyk/p/3250706.html

你可能感兴趣的文章
android 开发 View _15 导入一张图片将它裁剪成圆形 与 paint图层叠加处理详解
查看>>
地图大集合
查看>>
unity资源(移动版)提取 一点尝试
查看>>
简谈游戏场景灯光配置方案
查看>>
性能测试知识
查看>>
mybaitis配置信息
查看>>
使用shiro安全框架上传文件时用HttpSession获取ServletContext为null问题解决方法。
查看>>
数据可视化视频制作
查看>>
mysql 数据备份。pymysql模块
查看>>
FactoryMethod模式——设计模式学习
查看>>
Android中 AsyncTask
查看>>
原码、反码、补码和移码
查看>>
SQL存储过程与函数的区别
查看>>
vue项目配置使用flow类型检查
查看>>
@Resource和@Autowired区别
查看>>
VS2010打开就自动关闭问题解决
查看>>
python webdriver 测试框架-数据驱动txt文件驱动,带报告的例子
查看>>
动态代理相对于静态代理的优势
查看>>
持续部署之jenkins与gitlab(三)
查看>>
第二章 Jenkins安装与配置
查看>>