SGU107——987654321 problem
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、找n*n结果末尾是987654321的数。
先傻瓜式搜索,发现8位以下没有符合要求的;9位有4个,10位以上根据数学排列知识就搞定了。
最近在搞SGU,先从简单题目入手,碰到什么算法就搞什么算法。
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include<vector>
#include<map>
#include<deque>
#include<list>
using namespace std;
int main()
{
// for(int i=0;i<99999999;i++)
// if(i*i==987654321)
// printf("%d\n",i);
// for(long long i=sqrt(987654321.0);i<=999999999;++i)
// if( i*i%1000000000 == 987654321 )
// printf("%d\n",i);
//}
// 111111111
// 119357639
// 380642361
// 388888889
// 611111111
// 619357639
// 880642361
// 888888889 int n;
while (scanf("%d",&n)!=EOF)
{
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");
}
} }
SGU107——987654321 problem的更多相关文章
- sgu107. 987654321 problem 简单打表 难度:0
107. 987654321 problem time limit per test: 0.25 sec. memory limit per test: 4096 KB For given numbe ...
- 找规律 SGU 107 987654321 problem
题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=107 /* 题意:n位数的平方的后面几位为987654321的个数 尼玛,我看描述这 ...
- 数论 - SGU 107 987654321 problem
987654321 problem Problem's Link Mean: 略 analyse: 这道题目是道简单题. 不过的确要好好想一下: 通过简单的搜索可以知道,在N<9时答案一定为0, ...
- (水题)987654321 problem -- SGU 107
链接: http://vj.acmclub.cn/contest/view.action?cid=168#problem/G 时限:250MS 内存:4096KB 64位IO格式:%I ...
- SGU 107 987654321 problem【找规律】
题目链接: http://acm.sgu.ru/problem.php?contest=0&problem=107 题意: 平方后几位为987654321的n位数有多少个 分析: 虽然说是水题 ...
- sgu 107 987654321 problem
其实挺水的,因为两个数平方,只有固定的后面几位数会影响到最后结果的后面几位数.也就是说,如果想在平方之后尾数为987654321,那么就有固定的几个尾数在平方后会是这个数,打个表,发现 10^8 内 ...
- 987654321 problem - SGU 107(找规律)
题目大意:求n位数的平方的后几位结果是987654321的个数是多少. 分析:刚看到这道题的时候怀疑过有没有这样的数,于是暴力跑了一下,发现还真有,9位的数有8个,如下: i=111111111, i ...
- SGU 107
107. 987654321 problem time limit per test: 0.25 sec. memory limit per test: 4096 KB For given numbe ...
- SGU 乱搞日志
SGU 100 A+B :太神不会 SGU 101 Domino: 题目大意:有N张骨牌,两张骨牌有两面有0到6的数字,能相连当且仅当前后数字相同,问能否有将N张骨牌连接的方案?思路:裸的欧拉回路,注 ...
随机推荐
- yum安装软件时提示软件包没有签名
yum install [XXX] -y --nogpgcheck
- Seay工具分享
百度网盘:http://pan.baidu.com/share/home?uk=4045637737&view=share#category/type=0
- Android-java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
章出自:luchg技术交流 http://www.luchg.com 版权所有.本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源,谢谢. Android-java.lang.Runti ...
- GDB多进程调试(转)
http://www.cnblogs.com/ggjucheng/archive/2011/12/15/2288710.html GDB 是 linux 系统上常用的 c/c++ 调试工具,功能十分强 ...
- POJ 3264 Balanced Lineup(RMQ)
点我看题目 题意 :N头奶牛,Q次询问,然后给你每一头奶牛的身高,每一次询问都给你两个数,x y,代表着从x位置上的奶牛到y位置上的奶牛身高最高的和最矮的相差多少. 思路 : 刚好符合RMQ的那个求区 ...
- SPRING IN ACTION 第4版笔记-第五章Building Spring web applications-001-SpringMVC介绍
一. 二.用Java文件配置web application 1. package spittr.config; import org.springframework.web.servlet.suppo ...
- char和QChar(Unicode的编码与内存里的值还不是一回事)
char类型是c/c++中内置的类型,描述了1个字节的内存信息的解析.比如: char gemfield=’g’; 那么在由gemfield标记的这块内存的大小就是1个字节,信息就是01100111, ...
- 使用Html.fromHtml将html格式字符串应用到textview上面
在android中,有一个容易遗忘的Html.fromhtml方法,意思是可以将比如文本框中的字符串进行HTML格式化,支持的还是很多的, 但要注意的是要在string.xml中用<!--cda ...
- 安装db2 提示不是有效的win32应用程序?
问题已经解决了,就是版本的问题.我在官网上下载的最新版本(10.5),网上说是最新的版本不支持xp系统,完了我下了9.7的版本,安装没有一点点问题
- 结构体dict_field_t
typedef struct dict_field_struct dict_field_t; typedef struct dict_field_struct dict_field_t; /** Da ...