SGU 181 — X-Sequence

Posted on 五月 25th, 2008.

其实真的不难…自己找一下规律吧.
因为有mod m嘛…然后就几个一循环而已…

{
SGU 181; X-Sequence
- sqybi’s code
}
//for my winsty
program sgu181_sqybi;
  const
    mm = 1000;

  var
    n, i: longint;
    x, a, b, c, m, stop, r: int64;
    f, t: array[0..mm]of longint;

  begin
    readln(x, a, b, c, m, n);
    if n = 0 then begin
      writeln(x);
      halt;
    end;
    fillchar(f, sizeof(f), 0);
    stop := 0;
    for i:=1 to n do begin
      x := (a * x * x + b * x + c) mod m;
      if f[x] = 0 then begin
        f[x] := i;
        t[i] := x;
      end
      else begin
        stop := i;
        break;
      end;
    end;
    if stop = 0 then
      writeln(x)
    else begin
      dec(stop);
      r := (n - (f[x] - 1)) mod (stop - (f[x] - 1));
      if r = 0 then r := stop - (f[x] - 1);
      r := f[x] - 1 + r;
      writeln(t[r]);
    end;
  end.

阅读(189 次)

Make a Comment

Make A Comment: ( 5 so far )

blockquote and a tags work here.

5 Responses to “SGU 181 — X-Sequence”

RSS Feed for NOT A BLOG | sqybi Comments RSS Feed

你这个纯属侥幸吧
x0=1;alpha=1 beta=1 gama=2
m=3 则无法出现f=0的情况,会一直循环k次,会超时

notalent
五月 27th, 2008

不好意思,看错了

notalent
五月 27th, 2008

我是用wordpress的blogger,做奥赛。看到你抱怨标点的问题,推荐两个插件:

Quotmarks Replacer 禁用标点替换
http://sparanoid.com/taxonomy/blog/wordpress/quotmarks-replacer/

Syntax Highlighter代码高亮
http://wordpress.org/extend/plugins/google-syntax-highlighter/

希望帮到你 :grin:

沙渺
五月 27th, 2008

@notalent 呵呵 没关系 刚知道这么多人看这个blog啊…

sqybi
五月 27th, 2008

@沙渺
嗯…谢谢…不过72pines这里似乎不能上传插件(或许我不知道怎么传)…代码高亮的插件用WLW写文章发表时也有些繁琐 所以只好先凑合用了…
得赶快买个空间…

sqybi
五月 27th, 2008

Where's The Comment Form?

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