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

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;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值