zoukankan      html  css  js  c++  java
  • bzoj1406

    这道题很有意思

    我们解过线性同余方程,也解过同余方程

    这个则是求x^2≡1 (mod p)

    可以将问题转化为(x-1)(x+1)≡0 (mod p)

    然后我们穷举一下p的约数i,

    看i|x-1,p/i|x+1 或者i|x+1, p/i|x-1是否可行解

    然后排序去重即可

     1 var ans:array[0..1000010] of longint;
     2     a,n,i,b,t:longint;
     3     j:int64;
     4 
     5 procedure sort(l,r:longint);
     6   var i,j,x,y:longint;
     7   begin
     8     i:=l;
     9     j:=r;
    10     x:=ans[(l+r) shr 1];
    11     repeat
    12       while ans[i]<x do inc(i);
    13       while x<ans[j] do dec(j);
    14       if not(i>j) then
    15       begin
    16         y:=ans[i];
    17         ans[i]:=ans[j];
    18         ans[j]:=y;
    19         inc(i);
    20         j:=j-1;
    21       end;
    22     until i>j;
    23     if l<j then sort(l,j);
    24     if i<r then sort(i,r);
    25   end;
    26 
    27 begin
    28   readln(n);
    29   for i:=1 to trunc(sqrt(n)) do
    30     if n mod i=0 then
    31     begin
    32       b:=n div i;
    33       j:=1;
    34       while j<=n do
    35       begin
    36         if (j+1) mod i=0 then
    37         begin
    38           inc(t);
    39           ans[t]:=j;
    40         end;
    41         j:=j+b;  //保证x-1是b的倍数
    42       end;
    43       j:=b-1;
    44       while j<=n do
    45       begin
    46         if (j-1) mod i=0 then
    47         begin
    48           inc(t);
    49           ans[t]:=j;
    50         end;
    51         j:=j+b;
    52       end;
    53     end;
    54   sort(1,t);
    55   for i:=1 to t do
    56     if ans[i]<>ans[i-1] then writeln(ans[i]);
    57 end.
    View Code
  • 相关阅读:
    ios开发 <AppName>-Prefix.pch文件的用法详解
    iOS Block全面分析
    _weak typeof(self) weakSelf = self
    判断当前iOS设备的方法
    修改UITextfield的Placeholder字体的颜色
    uibutton实现左文字右图片
    apache Apache winnt_accept: Asynchronous AcceptEx failed 错误的解决
    android4.0 锁屏实现(转)
    android 代码设置、打开wifi热点及热点的连接(转)
    tomcat arp
  • 原文地址:https://www.cnblogs.com/phile/p/4473163.html
Copyright © 2011-2022 走看看