首页 > 其他 > 详细

SGU - 107 - 987654321 problem (简单数学!)

时间:2014-12-11 20:58:44      阅读:326      评论:0      收藏:0      [点我收藏+]

SGU - 107
Time Limit: 250MS   Memory Limit: 4096KB   64bit IO Format: %I64d & %I64u

 Status

Description

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

Source





还挺好玩的这题

思路:先直接暴力找出9位以内的符合题意的数,发现有8个,而且全都是9位数,依次是

//    111111111  
//    119357639  
//    380642361  
//    388888889  
//    611111111  
//    619357639  
//    880642361  
//    888888889 

8位数时,ans = 0,9位数时,ans = 8 

而根据排列组合有10位数时,ans=9*8,大于10位时,ans=9*(10^(n-10))*8。。


AC代码:


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	if(n<9)	printf("0\n");
	else if(n == 9)	printf("8\n");
	else 
	{
		printf("72");
		for(int i=11; i<=n; i++)
		{
			printf("0");
		}
		printf("\n");
	}
	return 0;
}




SGU - 107 - 987654321 problem (简单数学!)

原文:http://blog.csdn.net/u014355480/article/details/41870091

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!