您的位置:首页 > 其它

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

2014-12-11 17:52 267 查看
SGU - 107

987654321 problem

Time Limit: 250MSMemory Limit: 4096KB64bit IO Format: %I64d & %I64u
Submit 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: