Archive for 六月 10th, 2008

SGU 117 — Counting

Posted on 六月 10th, 2008.

给出n个数,判断它们的m次方能不能被k整除.对每个数和k分解质因数即可(注意对于每个数只需要分解k的因子).
{ SGU 117; Counting - sqybi’s code}//for my winstyprogram sgu117_sqybi;  const    nn = 10000;
  var    i, j, k, kk, l, n, m, s, t: longint;    a, b, p: array[1..nn]of longint;    f: boolean;
  begin    readln(n, m, k);    kk := k;    l := 0;    for i:=2 to kk do begin      if k = 1 then […]

Read Full Post | Make a Comment ( None so far )

SGU 113 — Nearly prime numbers

Posted on 六月 10th, 2008.

枚举一个素因子i,再判断n div i是不是素数就可以.数据太水了,我刚开始的程序有bug,枚举的不是素因子而是任意因子…我shaz…把自己的算法给忘了…刚才看了一下,枚举到的第一个因子一定是素因子(除了1最小的因子啊…),而只对这一个因子进行判断就可以…不用筛法,朴素判素就能AC.
{ SGU 113; Nearly prime numbers - sqybi’s code}//for my winstyprogram sgu113_sqybi;  var    f: boolean;    i, times, cases, n: longint;
  function prime(x: longint): boolean;    var      i: longint;    begin      prime := false;      for i:=2 to trunc(sqrt(x)) do        if x mod i = 0 then exit;      prime := true;    end;
  begin    readln(cases);    for […]

Read Full Post | Make a Comment ( None so far )

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 winstyprogram 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.
阅读(111 次)

Read Full Post | Make a Comment ( None so far )

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