SGU 107 C++ 数论
来源:互联网 发布:从哪买高仿手表知乎 编辑:程序博客网 时间:2024/06/05 05:47
原题是:求n位整数中平方的末尾数字为987654321的数的个数 。(1<=n<=1000000)
例如 :当n为9是,9位数111111111的平方为12345678987654321 ,其末尾数字为987654321,符合条件,题设就是求n位数中符合这个规律的数的个数。
先找规律,在9位数时有8个符合条件,8个以下没有符合条件的,9个以上时,由数论知识知,就有9*10^(n-10) *8 个,所以有以下的代码
#include<iostream>
using namespace std ;
int main()
{
int n ;
while(cin>>n)
{
if(n<9)
cout<<'0'<<endl ;
else if(n==9)
cout<<'8'<<endl ;
else
{
cout<<"72";
for(int i=0 ;i<n-10 ;i++)
cout<<'0' ;
cout<<endl ;
}
}
return 0 ;
}
0 0
- SGU 107 C++ 数论
- [SGU 107]987654321 problem (数论)
- SGU 107 987654321 problem (数论)
- SGU 117 Counting 数论
- SGU 119 数论
- SGU - 154 - Factorial (数论)
- SGU 126 Boxes(数论)
- ACM 数论 SGU 444Headstrong Student
- SGU - 102 - Coprimes (简单数论!)
- SGU 119 Magic Pairs(数论)
- SGU 105 Div 3(数论)
- SGU 108 Self-numbers 2(数论)
- SGU 118 Digital Root(数论)
- SGU 154 Factorial(数论+二分)
- SGU 107
- SGU 107
- 【数论】c
- SGU 116 Index of super-prime 数论+背包
- Android View 事件传递
- Star miscellaneous
- 第十一周 项目一:(1)存储班长信息的学生类
- 五、typedef和#define的用法与区别
- 字符串操作
- SGU 107 C++ 数论
- iOS应用发布流程
- 调教“光盘刻录大师”之“视频截取”
- 腾讯新闻评论数据爬取
- Android设备间Wifi通信
- vs2010搭建sqlite3编译环境
- HDFS 的Trash回收站功能的配置、使用
- Android应用中执行shell脚本的工具类的示例
- linux:SUID、SGID详解