传送门:【SGU】107. 987654321 problem
题目分析:平方只和后9位有关,当为9位时ans=8,大于等于十位时,最高位不能为0,除最后9位其他位均可以为零,ans=72000...(n-10个0)。
代码如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
//#include <cmath>
#include <queue>
using namespace std ;
typedef long long LL ;
#define rep( i , a , b ) for ( int i = a ; i < b ; ++ i )
#define For( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define rev( i , a , b ) for ( int i = a ; i >= b ; -- i )
#define travel( e , H , u ) for ( Edge* e = H[u] ; e ; e = e -> next )
#define clr( a , x ) memset ( a , x , sizeof a )
#define cpy( a , x ) memcpy ( a , x , sizeof a )
int n ;
void solve () {
if ( n <= 8 ) printf ( "0\n" ) ;
else if ( n == 9 ) printf ( "8\n" ) ;
else {
printf ( "72" ) ;
rep ( i , 10 , n ) printf ( "0" ) ;
printf ( "\n" ) ;
}
}
int main () {
while ( ~scanf ( "%d" , &n ) ) solve () ;
return 0 ;
}