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