浏览 3030 次
锁定老帖子 主题:一个猜手机号码的游戏用SQL解答
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-08-21
11位数字,其中0123456789都在里面,可以分解成两个不小于10000的素数相乘? 数量太多,暂时限制130打头的 set timi on lines 132 pages 50000 col n format 99999999999 with sp as( select 3 s from dual union all select 5 from dual union all select 7 from dual union all select 11 from dual union all select 13 from dual union all select 17 from dual union all select 19 from dual union all select 23 from dual union all select 29 from dual union all select 31 from dual union all select 37 from dual union all select 41 from dual union all select 43 from dual union all select 47 from dual union all select 53 from dual union all select 59 from dual union all select 61 from dual union all select 67 from dual union all select 71 from dual union all select 73 from dual union all select 79 from dual union all select 83 from dual union all select 89 from dual union all select 97 from dual union all select 101 from dual union all select 103 from dual union all select 107 from dual union all select 109 from dual union all select 113 from dual union all select 127 from dual union all select 131 from dual union all select 137 from dual union all select 139 from dual union all select 149 from dual union all select 151 from dual union all select 157 from dual union all select 163 from dual union all select 167 from dual union all select 173 from dual union all select 179 from dual union all select 181 from dual union all select 191 from dual union all select 193 from dual union all select 197 from dual union all select 199 from dual union all select 211 from dual union all select 223 from dual union all select 227 from dual union all select 229 from dual union all select 233 from dual union all select 239 from dual union all select 241 from dual union all select 251 from dual union all select 257 from dual union all select 263 from dual union all select 269 from dual union all select 271 from dual union all select 277 from dual union all select 281 from dual union all select 283 from dual union all select 293 from dual union all select 307 from dual union all select 311 from dual union all select 313 from dual union all select 317 from dual union all select 331 from dual union all select 337 from dual union all select 347 from dual union all select 349 from dual union all select 353 from dual union all select 359 from dual union all select 367 from dual union all select 373 from dual union all select 379 from dual union all select 383 from dual union all select 389 from dual union all select 397 from dual union all select 401 from dual union all select 409 from dual union all select 419 from dual union all select 421 from dual union all select 431 from dual union all select 433 from dual union all select 439 from dual union all select 443 from dual union all select 449 from dual union all select 457 from dual union all select 461 from dual union all select 463 from dual union all select 467 from dual union all select 479 from dual union all select 487 from dual union all select 491 from dual union all select 499 from dual union all select 503 from dual union all select 509 from dual union all select 521 from dual union all select 523 from dual union all select 541 from dual union all select 547 from dual union all select 557 from dual union all select 563 from dual union all select 569 from dual union all select 571 from dual union all select 577 from dual union all select 587 from dual union all select 593 from dual union all select 599 from dual union all select 601 from dual union all select 607 from dual union all select 613 from dual union all select 617 from dual union all select 619 from dual union all select 631 from dual union all select 641 from dual union all select 643 from dual union all select 647 from dual union all select 653 from dual union all select 659 from dual union all select 661 from dual union all select 673 from dual union all select 677 from dual union all select 683 from dual union all select 691 from dual union all select 701 from dual union all select 709 from dual union all select 719 from dual union all select 727 from dual union all select 733 from dual union all select 739 from dual union all select 743 from dual union all select 751 from dual union all select 757 from dual union all select 761 from dual union all select 769 from dual union all select 773 from dual union all select 787 from dual union all select 797 from dual union all select 809 from dual union all select 811 from dual union all select 821 from dual union all select 823 from dual union all select 827 from dual union all select 829 from dual union all select 839 from dual union all select 853 from dual union all select 857 from dual union all select 859 from dual union all select 863 from dual union all select 877 from dual union all select 881 from dual union all select 883 from dual union all select 887 from dual union all select 907 from dual union all select 911 from dual union all select 919 from dual union all select 929 from dual union all select 937 from dual union all select 941 from dual union all select 947 from dual union all select 953 from dual union all select 967 from dual union all select 971 from dual union all select 977 from dual union all select 983 from dual union all select 991 from dual union all select 997 from dual union all select 1009 from dual union all select 1013 from dual union all select 1019 from dual union all select 1021 from dual union all select 1031 from dual union all select 1033 from dual union all select 1039 from dual union all select 1049 from dual union all select 1051 from dual union all select 1061 from dual union all select 1063 from dual union all select 1069 from dual union all select 1087 from dual union all select 1091 from dual union all select 1093 from dual union all select 1097 from dual union all select 1103 from dual union all select 1109 from dual union all select 1117 from dual union all select 1123 from dual union all select 1129 from dual union all select 1151 from dual union all select 1153 from dual union all select 1163 from dual union all select 1171 from dual union all select 1181 from dual union all select 1187 from dual union all select 1193 from dual union all select 1201 from dual union all select 1213 from dual union all select 1217 from dual union all select 1223 from dual union all select 1229 from dual union all select 1231 from dual union all select 1237 from dual union all select 1249 from dual union all select 1259 from dual union all select 1277 from dual union all select 1279 from dual union all select 1283 from dual union all select 1289 from dual union all select 1291 from dual union all select 1297 from dual union all select 1301 from dual union all select 1303 from dual union all select 1307 from dual union all select 1319 from dual union all select 1321 from dual union all select 1327 from dual union all select 1361 from dual union all select 1367 from dual union all select 1373 from dual union all select 1381 from dual union all select 1399 from dual union all select 1409 from dual union all select 1423 from dual),-- 3~sqrt(2E10/1E4=2000000)的素数表,用来判断a.p,b.p是否素数的整数倍,2不用判断 pr as (select 9999+level*2 p from dual connect by level<=650000),--大的奇数因数 10001~2000000 pr2 as (select 9999+level*2 p from dual connect by level<=(141439-9999)/2)--小的奇数因数 10001~141439 select a.p,b.p,a.p*b.p n from pr a,pr2 b where a.p>=b.p and b.p>=130E8/a.p and b.p<=131E8/a.p and substr(to_char(a.p*b.p),2,1)IN('3','5','8') --and not exists(select 1 from sp c where mod(a.p,c.s)=0) --and not exists(select 1 from sp c where mod(b.p,c.s)=0) and not exists(select 1 from sp c where c.s<=a.p/3 and mod(a.p,c.s)=0) and not exists(select 1 from sp c where c.s<=b.p/3 and mod(b.p,c.s)=0) /*假定是中国手机号都是1开头*/ and a.p*b.p>=130E8 and a.p*b.p<131E8 and instr(to_char(a.p*b.p),'0')>1 --and instr(to_char(a.p*b.p),'1')>1 /*第一位必须是1,因此不用判断*/ and instr(to_char(a.p*b.p),'2')>1 and instr(to_char(a.p*b.p),'3')>1 and instr(to_char(a.p*b.p),'4')>1 and instr(to_char(a.p*b.p),'5')>1 and instr(to_char(a.p*b.p),'6')>1 and instr(to_char(a.p*b.p),'7')>1 and instr(to_char(a.p*b.p),'8')>1 and instr(to_char(a.p*b.p),'9')>1 ; 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |