SGU 107 — 987654321 problem

Posted on 六月 10th, 2008.

可以发现,一个数平方的最后9位只和这个数的最后9位有关.对1~9位数随便写个小程序枚举一下,就可发现:对于1位数到8位数,没有任何符合条件;对于9位数,有8个数符合条件;对于n位数(n>9),最高位有9种(1~9),后9位有8种,剩余n-10位每位10种(0~9),总共72*10^(n-10)种.

{
SGU 107; 987654321 Problem
- sqybi’s code
}
//for my winsty
program sgu107_sqybi;
  var
    i, n: longint;

  begin
    readln(n);
    if n <= 8 then
      writeln(0)
    else if n = 9 then
      writeln(8)
    else begin
      write(72);
      for i:=1 to n-10 do write(0);
    end;
  end.

阅读(77 次)

Make a Comment

Make A Comment: ( None so far )

blockquote and a tags work here.

Liked it here?
Why not try sites on the blogroll...