-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7.go
76 lines (67 loc) · 1.29 KB
/
7.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"flag"
_ "os"
"fmt"
_ "math"
)
const block = uint64(1)<<25
type LS struct {
cap uint64
in [][]uint64
}
func x(n uint64) uint64 {
return n / 2 / 64 / block
}
func y(n uint64) uint64 {
return (n / 2 / 64) % block
}
func z(n uint64) uint64 {
return (n/2) % 64
}
func NewLs(cap uint64) *LS {
r := x(cap-1)+1
in := make([][]uint64, r)
return &LS{cap, in}
}
func (ls *LS) Get(i uint64) bool {
x := x(i)
if len(ls.in[x]) == 0 {
return false
}
y := y(i)
z := z(i)
return (ls.in[x][y] & (uint64(1) << z)) != 0
}
func (ls *LS) Set(i uint64) {
x := x(i)
if len(ls.in[x]) == 0 {
ls.in[x] = make([]uint64, block)
}
y := y(i)
z := z(i)
ls.in[x][y] |= (uint64(1) << z)
}
var data = flag.Uint64("data", uint64(0), "input data")
var size = flag.Uint64("size", uint64(0), "input data")
func main(){
flag.Parse()
fmt.Printf(" find para %d %d", *data, *size)
ls := NewLs(*size + 1)
cnt := uint64(1)
for i:=uint64(3); i<=*size; i+=2 {
if ls.Get(i) {
continue
}
cnt ++
//fmt.Printf("data %d found %d cnt %d\n", *data, i, cnt)
if cnt == *data {
fmt.Printf("data %d result %d cnt %d\n", *data, i,cnt)
return
}
for j:=i*i;j<=*size; j+=2*i {
ls.Set(j)
}
}
fmt.Printf("not found %d", cnt)
}