• 瀏覽: 5,832
  • 回覆: 48
range 100-20000.

public static int randomPrime(){
        boolean prime = true;         int i=2;    int p = (int) (100 + (Math.random() *20000));
    while (i<=Math.sqrt(p)){   
            if (p%i==0){                    p = (int) (100 + (Math.random() *20000));                    prime=false;                    }             i++;            }    if (prime) {
      System.out.println("p : "+ p);
    }   
}



Please use code tag to show your code.


Prime checking裡面為何要再抽新數字...???

假設第一次抽出數字81 (((當係啦
當i == 3時p%i == 0即又再抽出新數字...假設是36
這時i依然在下個數字即4開始做test

這裡不是每次抽新數字時都重新做test的

另外...如果prime set左做false...就一直是false沒機會行output果行code






佢段碼重有其他問題,就咁講晒佢聽,相信佢唔會明。
我諗逐樣講會好尐。
但第一點要佢明白,貼程式碼上嚟,係要用代碼標籤。

P.S. 轉戶口?



[隱藏]
是啊....另一邊壇個當了版主....心思思想換...

樓主段code不就是要重寫嗎...???XD



係邊個版呀?

樓主係要重寫,但係學習應包括埋點樣問嘢,係咪?



引用:
原帖由 fitcat07 於 2013-7-18 02:55 PM 發表
係邊個版呀?

樓主係要重寫,但係學習應包括埋點樣問嘢,係咪?
同人創作~

琴晚諗到一點點玩意.... (((要挑戰Zuckerberg..???
好耐冇寫過網頁...不過試下可唔可以一日內寫好

[ 本帖最後由 Susan﹏汪汪 於 2013-7-18 03:01 PM 編輯 ]



我諗左一輪都唔知點解
原來 prime num = 質數..

my english is so poor.

but the above codes should retain a true/false result of the last MAX random num for increasing the efficiency. (staring looping from last MAX random num)

[ 本帖最後由 p_net 於 2013-7-18 06:56 PM 編輯 ]



引用:
原帖由 Susan﹏汪汪 於 2013-7-18 02:58 PM 發表
同人創作~

琴晚諗到一點點玩意.... (((要挑戰Zuckerberg..???
好耐冇寫過網頁...不過試下可唔可以一日內寫好
a webpage can be finished in one single night???

i cant beleive even thought you are using any existing component or framework..



[隱藏]
引用:
原帖由 p_net 於 2013-7-18 06:54 PM 發表
a webpage can be finished in one single night???

i cant beleive even thought you are using any existing component or framework..
沒試過怎麼知道... (((當年他都是用了一晚來做...



引用:
原帖由 Susan﹏汪汪 於 2013-7-18 07:01 PM 發表
沒試過怎麼知道... (((當年他都是用了一晚來做...
you also say "at that time", i once surf its page at that time, the outlook is simple, not ajax, so it might be possible to finish with that quality (although i think that he was also blowing water for just using a night to finish). With current scale, i think you can even not "copy" it within a year.



引用:
原帖由 p_net 於 2013-7-18 07:08 PM 發表
you also say "at that time", i once surf its page at that time, the outlook is simple, not ajax, so it might be possible to finish with that quality (although i think that he was also blowing water fo ...
所以才說是用一日來做架構



引用:
原帖由 Susan﹏汪汪 於 2013-7-18 07:37 PM 發表
所以才說是用一日來做架構
for just db efficiency, it has no way to beat it down...

try hard...



Just practicing Linq
複製內容到剪貼板
代碼:
using System;
using System.Linq;

class Program {
    static void Main() {
        var query = Enumerable.Range(100, 20000 - 100 + 1)
                        .Where(i => i % 2 != 0)
                        .Where(i =>
                            Enumerable.Range(2, (int)Math.Sqrt(i) - 1)
                                        .All(j => i % j != 0));


        int total = query.Count();
        Func<int, int> FindPrime = x => query.Skip(x).First();

        int random = new Random().Next(total);
        Console.WriteLine("{0}", FindPrime(random));
    }
}



[隱藏]
其實如果唔係由2開始抽的話...可以淨抽單數的






鍵盤翻頁
左右
[按此隱藏 Google 建議的相符內容]