找出100以内所有的索数
条件:不能用循环  结果是这样的
1
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97

解决方案 »

  1.   


    declare @t table (
    a int
    )insert @t select a+10*b+1
    from (
    select 1 as a
    union all select 2
    union all select 3
    union all select 4
    union all select 5
    union all select 6
    union all select 7
    union all select 8
    union all select 9
    union all select 0
    ) as a,(
    select 1 as b
    union all select 2
    union all select 3
    union all select 4
    union all select 5
    union all select 6
    union all select 7
    union all select 8
    union all select 9
    union all select 0
    ) as b
    where a+10*b+1<>1delete a
    from @t a,@t b
    where a.a % b.a =0
    and a.a<>b.aselect * from @t order by a--结果
    a           
    ----------- 
    2
    3
    5
    7
    11
    13
    17
    19
    23
    29
    31
    37
    41
    43
    47
    53
    59
    61
    67
    71
    73
    79
    83
    89
    97(所影响的行数为 25 行)
      

  2.   

    if(("我没记错")&&("质数与素数定义未改变"))
    JOptionPane.showMessageDialog(null,"1既不是质数也不是素数");
      

  3.   


    select * 
    from 
    (
    select a.id*10+b.id + 1  id
    from (select 1 id union all select 2 union all select 3 union all select 4 union all select 5 
    union all select 6 union all select 7 union all select 8 union all select 9 union all select 0  )a 
    join (select 1 id union all select 2 union all select 3 union all select 4 union all select 5 
    union all select 6 union all select 7 union all select 8 union all select 9 union all select 0  )b 
    on 1=1 
    ) t
    where not exists (select 1 from 
    (
    select a.id*10+b.id + 1  id
    from (select 1 id union all select 2 union all select 3 union all select 4 union all select 5 
    union all select 6 union all select 7 union all select 8 union all select 9 union all select 0  )a 
    join (select 1 id union all select 2 union all select 3 union all select 4 union all select 5 
    union all select 6 union all select 7 union all select 8 union all select 9 union all select 0  )b 
    on 1=1 
    ) tmp 
    where id >1 and  t.id >= id *id and t.id%id = 0
    )
    and id > 1 
    order by id 
    id
    -----------
    2
    3
    5
    7
    11
    13
    17
    19
    23
    29
    31
    37
    41
    43
    47
    53
    59
    61
    67
    71
    73
    79
    83
    89
    97(25 row(s) affected)
      

  4.   

    为了提高速度,
    and a.a<>b.a
    --〉
    and a.a>b.a
      

  5.   

    再BS 0分贴, LZ忍不住加了200分,
    弟兄再狂顶,成精华贴了,嘻嘻
      

  6.   

    void  PrintNum(int i,int j)
    {
       if(j==1)printf(i);
       if(i/j!=(int)i/j)
       {
          PrintNum(i,j--);
       }
       else
       {
          printNum(--i,(int)sqrt(--i));
       }
    }printNum(100,10);
    不知道对不对,哈哈.也没有测试.
      

  7.   

    应该中间再加一句
    if (i==1) return;
    忘了写终止了
      

  8.   

    刚才开了个C#的环境测试了一下通过了.不知道C中如何留给大家去做吧.呵呵
             static void Main(string[] args)
            {            PrintNum(100, 10);
                Console.Read();
            }        private static void PrintNum(int i, int j)
            {
                if (j == 1)
                {
                    Console.Write(i);
                    Console.WriteLine();
                }
                if (i == 1)
                {
                    Console.Write(i);
                    return;
                }
                decimal m = (decimal)i / j;
                if ( m!= (int)(i / j))
                {
                    PrintNum(i, --j);
                }
                else
                {
                    PrintNum(--i, (int)Math.Sqrt(--i));
                }
            } 
      

  9.   


    这是别人写的两种方法
    select top 100 px=identity(int,1,1) into # from sysobjects
    --方法1取模
    select px from # where px<>1 and px%2 <>0  and px%3<>0 and px%5<>0 and px%7<>0 or px=2 or px=5 or px=3 or px=7 
    --方法2不等于乘积
    select * from #
           where px>1 and px not in
           (select a.px*b.px from # a, # b where a.px>1 and b.px>1)
     
      

  10.   

    进来BS一下零分贴 + 不JF