472,133 Members | 1,162 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

loop for finding possible odd divisors

I'm making a prime finder another thing I'd like is a loop to check all possible odd factors if I can do that i can find all primes under 18 quintillion I think and store them in files ( yes I have nearly 200 GB of space left). also thanks for the thread on finding position in a file it helped me stop the file getting to big too open in MS-DOS

Expand|Select|Wrap|Line Numbers
  1. //---------------------------------------------------------------------------
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #pragma hdrstop
  5.  
  6. #include <tchar.h>
  7. //---------------------------------------------------------------------------
  8.  
  9. #pragma argsused
  10. int _tmain(int argc, _TCHAR* argv[])
  11. {
  12. unsigned long long int i;
  13. int fs;
  14. int prime=0;
  15.     FILE *fp;
  16.     size_t count;
  17.     fp = fopen("primes.txt", "w+");
  18. for (i =3; i <1000000000; i=i+2) {
  19. fseek (fp,0,SEEK_END);
  20. if (ftell(fp)<4000000000) {
  21. if (i%3!=0 || i==3) {
  22. if (i%5!=0 || i==5) {
  23. if (i%7!=0 || i==7) {
  24. if (i%11!=0 || i==11) {
  25. if (i%13!=0 || i==13) {
  26. if (i%17!=0 || i==17) {
  27. if (i%19!=0 || i==19) {
  28. if (i%23!=0 || i==23) {
  29. if (i%29!=0 || i==29) {
  30. if (i%31!=0 || i==31) {
  31. if (i%37!=0 || i==37) {
  32. if (i%41!=0 || i==41) {
  33. if (i%43!=0 || i==43) {
  34. if (i%47!=0 || i==47) {
  35. if (i%53!=0 || i==53) {
  36. if (i%59!=0 || i==59) {
  37. if (i%61!=0 || i==61) {
  38. if (i%67!=0 || i==67) {
  39. if (i%71!=0 || i==71) {
  40. if (i%73!=0 || i==73) {
  41. if (i%79!=0 || i==79) {
  42. if (i%83!=0 || i==83) {
  43. if (i%89!=0 || i==89) {
  44. if (i%97!=0 || i==97) {
  45. if (i%101!=0 || i==101) {
  46. if (i%103!=0 || i==103) {
  47. if (i%107!=0 || i==107) {
  48. if (i%109!=0 || i==109) {
  49. if (i%113!=0 || i==113) {
  50. if (i%127!=0 || i==127) {
  51. if (i%131!=0 || i==131) {
  52. if (i%137!=0 || i==137) {
  53. if (i%139!=0 || i==139) {
  54. if (i%149!=0 || i==149) {
  55. if (i%151!=0 || i==151) {
  56. if (i%157!=0 || i==157) {
  57. if (i%163!=0 || i==163) {
  58. if (i%167!=0 || i==167) {
  59. if (i%173!=0 || i==173) {
  60. if (i%179!=0 || i==179) {
  61. if (i%181!=0 || i==181) {
  62. if (i%191!=0 || i==191) {
  63. if (i%193!=0 || i==193) {
  64. if (i%197!=0 || i==197) {
  65. if (i%199!=0 || i==199) {
  66. if (i%211!=0 || i==211) {
  67. if (i%223!=0 || i==223) {
  68. if (i%227!=0 || i==227) {
  69. if (i%229!=0 || i==229) {
  70. if (i%233!=0 || i==233) {
  71. if (i%239!=0 || i==239) {
  72. if (i%241!=0 || i==241) {
  73. if (i%251!=0 || i==251) {
  74. if (i%257!=0 || i==257) {
  75. if (i%263!=0 || i==263) {
  76. if (i%269!=0 || i==269) {
  77. if (i%271!=0 || i==271) {
  78. if (i%277!=0 || i==277) {
  79. if (i%281!=0 || i==281) {
  80. if (i%283!=0 || i==283) {
  81. if (i%293!=0 || i==293) {
  82. if (i%307!=0 || i==307) {
  83. if (i%311!=0 || i==311) {
  84. if (i%313!=0 || i==313) {
  85. if (i%317!=0 || i==317) {
  86. if (i%331!=0 || i==331) {
  87. if (i%337!=0 || i==337) {
  88. if (i%347!=0 || i==347) {
  89. if (i%349!=0 || i==349) {
  90. if (i%353!=0 || i==353) {
  91. if (i%359!=0 || i==359) {
  92. if (i%367!=0 || i==367) {
  93. if (i%373!=0 || i==373) {
  94. if (i%379!=0 || i==379) {
  95. if (i%383!=0 || i==383) {
  96. if (i%389!=0 || i==389) {
  97. if (i%397!=0 || i==397) {
  98. if (i%401!=0 || i==401) {
  99. if (i%409!=0 || i==409) {
  100. if (i%419!=0 || i==419) {
  101. if (i%421!=0 || i==421) {
  102. if (i%431!=0 || i==431) {
  103. if (i%433!=0 || i==433) {
  104. if (i%439!=0 || i==439) {
  105. if (i%443!=0 || i==443) {
  106. if (i%449!=0 || i==449) {
  107. if (i%457!=0 || i==457) {
  108. if (i%461!=0 || i==461) {
  109. if (i%463!=0 || i==463) {
  110. if (i%467!=0 || i==467) {
  111. if (i%479!=0 || i==479) {
  112. if (i%487!=0 || i==487) {
  113. if (i%491!=0 || i==491) {
  114. if (i%499!=0 || i==499) {
  115. if (i%503!=0 || i==503) {
  116. if (i%509!=0 || i==509) {
  117. if (i%521!=0 || i==521) {
  118. if (i%523!=0 || i==523) {
  119. if (i%541!=0 || i==541) {
  120. if (i%547!=0 || i==547) {
  121. if (i%557!=0 || i==557) {
  122. if (i%563!=0 || i==563) {
  123. if (i%569!=0 || i==569) {
  124. if (i%571!=0 || i==571) {
  125. if (i%577!=0 || i==577) {
  126. if (i%587!=0 || i==587) {
  127. if (i%593!=0 || i==593) {
  128. if (i%599!=0 || i==599) {
  129. if (i%601!=0 || i==601) {
  130. if (i%607!=0 || i==607) {
  131. if (i%613!=0 || i==613) {
  132. if (i%617!=0 || i==617) {
  133. if (i%619!=0 || i==619) {
  134. if (i%631!=0 || i==631) {
  135. if (i%641!=0 || i==641) {
  136. if (i%643!=0 || i==643) {
  137. if (i%647!=0 || i==647) {
  138. if (i%653!=0 || i==653) {
  139. if (i%659!=0 || i==659) {
  140. if (i%661!=0 || i==661) {
  141. if (i%673!=0 || i==673) {
  142. if (i%677!=0 || i==677) {
  143. if (i%683!=0 || i==683) {
  144. if (i%691!=0 || i==691) {
  145. if (i%701!=0 || i==701) {
  146. if (i%709!=0 || i==709) {
  147. if (i%719!=0 || i==719) {
  148. if (i%727!=0 || i==727) {
  149. if (i%733!=0 || i==733) {
  150. if (i%739!=0 || i==739) {
  151. if (i%743!=0 || i==743) {
  152. if (i%751!=0 || i==751) {
  153. if (i%757!=0 || i==757) {
  154. if (i%761!=0 || i==761) {
  155. if (i%769!=0 || i==769) {
  156. if (i%773!=0 || i==773) {
  157. if (i%787!=0 || i==787) {
  158. if (i%797!=0 || i==797) {
  159. if (i%809!=0 || i==809) {
  160. if (i%811!=0 || i==811) {
  161. if (i%821!=0 || i==821) {
  162. if (i%823!=0 || i==823) {
  163. if (i%827!=0 || i==827) {
  164. if (i%829!=0 || i==829) {
  165. if (i%839!=0 || i==839) {
  166. if (i%853!=0 || i==853) {
  167. if (i%857!=0 || i==857) {
  168. if (i%859!=0 || i==859) {
  169. if (i%863!=0 || i==863) {
  170. if (i%877!=0 || i==877) {
  171. if (i%881!=0 || i==881) {
  172. if (i%883!=0 || i==883) {
  173. if (i%887!=0 || i==887) {
  174. if (i%907!=0 || i==907) {
  175. if (i%911!=0 || i==911) {
  176. if (i%919!=0 || i==919) {
  177. if (i%929!=0 || i==929) {
  178. if (i%937!=0 || i==937) {
  179. if (i%941!=0 || i==941) {
  180. if (i%947!=0 || i==947) {
  181. if (i%953!=0 || i==953) {
  182. if (i%967!=0 || i==967) {
  183. if (i%971!=0 || i==971) {
  184. if (i%977!=0 || i==977) {
  185. if (i%991!=0 || i==991) {
  186. if (i%997!=0 || i==997) {
  187. if (i%1009!=0 || i==1009) {
  188. if (i%1013!=0 || i==1013) {
  189. if (i%1019!=0 || i==1019) {
  190. if (i%1021!=0 || i==1021) {
  191. if (i%1031!=0 || i==1031) {
  192. if (i%1033!=0 || i==1033) {
  193. if (i%1039!=0 || i==1039) {
  194. if (i%1049!=0 || i==1049) {
  195. if (i%1051!=0 || i==1051) {
  196. if (i%1061!=0 || i==1061) {
  197. if (i%1063!=0 || i==1063) {
  198. if (i%1069!=0 || i==1069) {
  199. if (i%1087!=0 || i==1087) {
  200. if (i%1091!=0 || i==1091) {
  201. if (i%1093!=0 || i==1093) {
  202. if (i%1097!=0 || i==1097) {
  203. if (i%1103!=0 || i==1103) {
  204. if (i%1109!=0 || i==1109) {
  205. if (i%1117!=0 || i==1117) {
  206. if (i%1123!=0 || i==1123) {
  207. if (i%1129!=0 || i==1129) {
  208. if (i%1151!=0 || i==1151) {
  209. if (i%1153!=0 || i==1153) {
  210. if (i%1163!=0 || i==1163) {
  211. if (i%1171!=0 || i==1171) {
  212. if (i%1181!=0 || i==1181) {
  213. if (i%1187!=0 || i==1187) {
  214. if (i%1193!=0 || i==1193) {
  215. if (i%1201!=0 || i==1201) {
  216. if (i%1213!=0 || i==1213) {
  217. if (i%1217!=0 || i==1217) {
  218. if (i%1223!=0 || i==1223) {
  219. if (i%1229!=0 || i==1229) {
  220. if (i%1231!=0 || i==1231) {
  221. if (i%1237!=0 || i==1237) {
  222. if (i%1249!=0 || i==1249) {
  223. if (i%1259!=0 || i==1259) {
  224. if (i%1277!=0 || i==1277) {
  225. if (i%1279!=0 || i==1279) {
  226. if (i%1283!=0 || i==1283) {
  227. if (i%1289!=0 || i==1289) {
  228. if (i%1291!=0 || i==1291) {
  229. if (i%1297!=0 || i==1297) {
  230. if (i%1301!=0 || i==1301) {
  231. if (i%1303!=0 || i==1303) {
  232. if (i%1307!=0 || i==1307) {
  233. if (i%1319!=0 || i==1319) {
  234. if (i%1321!=0 || i==1321) {
  235. if (i%1327!=0 || i==1327) {
  236. if (i%1361!=0 || i==1361) {
  237. if (i%1367!=0 || i==1367) {
  238. if (i%1373!=0 || i==1373) {
  239. if (i%1381!=0 || i==1381) {
  240. if (i%1399!=0 || i==1399) {
  241. if (i%1409!=0 || i==1409) {
  242. if (i%1423!=0 || i==1423) {
  243. if (i%1427!=0 || i==1427) {
  244. if (i%1429!=0 || i==1429) {
  245. if (i%1433!=0 || i==1433) {
  246. if (i%1439!=0 || i==1439) {
  247. if (i%1447!=0 || i==1447) {
  248. if (i%1451!=0 || i==1451) {
  249. if (i%1453!=0 || i==1453) {
  250. if (i%1459!=0 || i==1459) {
  251. if (i%1471!=0 || i==1471) {
  252. if (i%1481!=0 || i==1481) {
  253. if (i%1483!=0 || i==1483) {
  254. if (i%1487!=0 || i==1487) {
  255. if (i%1489!=0 || i==1489) {
  256. if (i%1493!=0 || i==1493) {
  257. if (i%1499!=0 || i==1499) {
  258. if (i%1511!=0 || i==1511) {
  259. if (i%677!=0 || i==677) {
  260. if (i%683!=0 || i==683) {
  261. if (i%691!=0 || i==691) {
  262. if (i%701!=0 || i==701) {
  263. if (i%3!=0 || i==3) {
  264. if (i%5!=0 || i==5) {
  265. if (i%7!=0 || i==7) {
  266. if (i%11!=0 || i==11) {
  267. if (i%13!=0 || i==13) {
  268. if (i%17!=0 || i==17) {
  269. if (i%19!=0 || i==19) {
  270. if (i%23!=0 || i==23) {
  271. if (i%29!=0 || i==29) {
  272. if (i%31!=0 || i==31) {
  273. if (i%37!=0 || i==37) {
  274. if (i%41!=0 || i==41) {
  275. if (i%43!=0 || i==43) {
  276. if (i%47!=0 || i==47) {
  277. if (i%53!=0 || i==53) {
  278. if (i%59!=0 || i==59) {
  279. if (i%61!=0 || i==61) {
  280. if (i%67!=0 || i==67) {
  281. if (i%71!=0 || i==71) {
  282. if (i%73!=0 || i==73) {
  283. if (i%79!=0 || i==79) {
  284. if (i%83!=0 || i==83) {
  285. if (i%89!=0 || i==89) {
  286. if (i%97!=0 || i==97) {
  287. if (i%101!=0 || i==101) {
  288. if (i%103!=0 || i==103) {
  289. if (i%107!=0 || i==107) {
  290. if (i%109!=0 || i==109) {
  291. if (i%113!=0 || i==113) {
  292. if (i%127!=0 || i==127) {
  293. if (i%131!=0 || i==131) {
  294. if (i%137!=0 || i==137) {
  295. if (i%139!=0 || i==139) {
  296. if (i%149!=0 || i==149) {
  297. if (i%151!=0 || i==151) {
  298. if (i%157!=0 || i==157) {
  299. if (i%163!=0 || i==163) {
  300. if (i%167!=0 || i==167) {
  301. if (i%173!=0 || i==173) {
  302. if (i%179!=0 || i==179) {
  303. if (i%181!=0 || i==181) {
  304. if (i%191!=0 || i==191) {
  305. if (i%193!=0 || i==193) {
  306. if (i%197!=0 || i==197) {
  307. if (i%199!=0 || i==199) {
  308. if (i%211!=0 || i==211) {
  309. if (i%223!=0 || i==223) {
  310. if (i%227!=0 || i==227) {
  311. if (i%229!=0 || i==229) {
  312. if (i%233!=0 || i==233) {
  313. if (i%239!=0 || i==239) {
  314. if (i%241!=0 || i==241) {
  315. if (i%251!=0 || i==251) {
  316. if (i%257!=0 || i==257) {
  317. if (i%263!=0 || i==263) {
  318. if (i%269!=0 || i==269) {
  319. if (i%271!=0 || i==271) {
  320. if (i%277!=0 || i==277) {
  321. if (i%281!=0 || i==281) {
  322. if (i%283!=0 || i==283) {
  323. if (i%293!=0 || i==293) {
  324. if (i%307!=0 || i==307) {
  325. if (i%311!=0 || i==311) {
  326. if (i%313!=0 || i==313) {
  327. if (i%317!=0 || i==317) {
  328. if (i%331!=0 || i==331) {
  329. if (i%337!=0 || i==337) {
  330. if (i%347!=0 || i==347) {
  331. if (i%349!=0 || i==349) {
  332. if (i%353!=0 || i==353) {
  333. if (i%359!=0 || i==359) {
  334. if (i%367!=0 || i==367) {
  335. if (i%373!=0 || i==373) {
  336. if (i%379!=0 || i==379) {
  337. if (i%383!=0 || i==383) {
  338. if (i%389!=0 || i==389) {
  339. if (i%397!=0 || i==397) {
  340. if (i%401!=0 || i==401) {
  341. if (i%409!=0 || i==409) {
  342. if (i%419!=0 || i==419) {
  343. if (i%421!=0 || i==421) {
  344. if (i%431!=0 || i==431) {
  345. if (i%433!=0 || i==433) {
  346. if (i%439!=0 || i==439) {
  347. if (i%443!=0 || i==443) {
  348. if (i%449!=0 || i==449) {
  349. if (i%457!=0 || i==457) {
  350. if (i%461!=0 || i==461) {
  351. if (i%463!=0 || i==463) {
  352. if (i%467!=0 || i==467) {
  353. if (i%479!=0 || i==479) {
  354. if (i%487!=0 || i==487) {
  355. if (i%491!=0 || i==491) {
  356. if (i%499!=0 || i==499) {
  357. if (i%503!=0 || i==503) {
  358. if (i%509!=0 || i==509) {
  359. if (i%521!=0 || i==521) {
  360. if (i%523!=0 || i==523) {
  361. if (i%541!=0 || i==541) {
  362. if (i%547!=0 || i==547) {
  363. if (i%557!=0 || i==557) {
  364. if (i%563!=0 || i==563) {
  365. if (i%569!=0 || i==569) {
  366. if (i%571!=0 || i==571) {
  367. if (i%577!=0 || i==577) {
  368. if (i%587!=0 || i==587) {
  369. if (i%593!=0 || i==593) {
  370. if (i%599!=0 || i==599) {
  371. if (i%601!=0 || i==601) {
  372. if (i%607!=0 || i==607) {
  373. if (i%613!=0 || i==613) {
  374. if (i%617!=0 || i==617) {
  375. if (i%619!=0 || i==619) {
  376. if (i%631!=0 || i==631) {
  377. if (i%641!=0 || i==641) {
  378. if (i%643!=0 || i==643) {
  379. if (i%647!=0 || i==647) {
  380. if (i%653!=0 || i==653) {
  381. if (i%659!=0 || i==659) {
  382. if (i%661!=0 || i==661) {
  383. if (i%673!=0 || i==673) {
  384. if (i%677!=0 || i==677) {
  385. if (i%683!=0 || i==683) {
  386. if (i%691!=0 || i==691) {
  387. if (i%701!=0 || i==701) {
  388. if (i%709!=0 || i==709) {
  389. if (i%719!=0 || i==719) {
  390. if (i%727!=0 || i==727) {
  391. if (i%733!=0 || i==733) {
  392. if (i%739!=0 || i==739) {
  393. if (i%743!=0 || i==743) {
  394. if (i%751!=0 || i==751) {
  395. if (i%757!=0 || i==757) {
  396. if (i%761!=0 || i==761) {
  397. if (i%769!=0 || i==769) {
  398. if (i%773!=0 || i==773) {
  399. if (i%787!=0 || i==787) {
  400. if (i%797!=0 || i==797) {
  401. if (i%809!=0 || i==809) {
  402. if (i%811!=0 || i==811) {
  403. if (i%821!=0 || i==821) {
  404. if (i%823!=0 || i==823) {
  405. if (i%827!=0 || i==827) {
  406. if (i%829!=0 || i==829) {
  407. if (i%839!=0 || i==839) {
  408. if (i%853!=0 || i==853) {
  409. if (i%857!=0 || i==857) {
  410. if (i%859!=0 || i==859) {
  411. if (i%863!=0 || i==863) {
  412. if (i%877!=0 || i==877) {
  413. if (i%881!=0 || i==881) {
  414. if (i%883!=0 || i==883) {
  415. if (i%887!=0 || i==887) {
  416. if (i%907!=0 || i==907) {
  417. if (i%911!=0 || i==911) {
  418. if (i%919!=0 || i==919) {
  419. if (i%929!=0 || i==929) {
  420. if (i%937!=0 || i==937) {
  421. if (i%941!=0 || i==941) {
  422. if (i%947!=0 || i==947) {
  423. if (i%953!=0 || i==953) {
  424. if (i%967!=0 || i==967) {
  425. if (i%971!=0 || i==971) {
  426. if (i%977!=0 || i==977) {
  427. if (i%991!=0 || i==991) {
  428. if (i%997!=0 || i==997) {
  429. if (i%1009!=0 || i==1009) {
  430. fprintf(fp, "%d,",i);
  431. prime=prime+1;
  432. }
  433. }
  434. }
  435. }
  436. }
  437. }
  438. }
  439. }
  440. }
  441. }
  442. }
  443. }
  444. }
  445. }
  446. }
  447. }
  448. }
  449. }
  450. }
  451. }
  452. }
  453. }
  454. }
  455. }
  456. }
  457. }
  458. }
  459. }
  460. }
  461. }
  462. }
  463. }
  464. }
  465. }
  466. }
  467. }
  468. }
  469. }
  470. }
  471. }
  472. }
  473. }
  474. }
  475. }
  476. }
  477. }
  478. }
  479. }
  480. }
  481. }
  482. }
  483. }
  484. }
  485. }
  486. }
  487. }
  488. }
  489. }
  490. }
  491. }
  492. }
  493. }
  494. }
  495. }
  496. }
  497. }
  498. }
  499. }
  500. }
  501. }
  502. }
  503. }
  504. }
  505. }
  506. }
  507. }
  508. }
  509. }
  510. }
  511. }
  512. }
  513. }
  514. }
  515. }
  516. }
  517. }
  518. }
  519. }
  520. }
  521. }
  522. }
  523. }
  524. }
  525. }
  526. }
  527. }
  528. }
  529. }
  530. }
  531. }
  532. }
  533. }
  534. }
  535. }
  536. }
  537. }
  538. }
  539. }
  540. }
  541. }
  542. }
  543. }
  544. }
  545. }
  546. }
  547. }
  548. }
  549. }
  550. }
  551. }
  552. }
  553. }
  554. }
  555. }
  556. }
  557. }
  558. }
  559. }
  560. }
  561. }
  562. }
  563. }
  564. }
  565. }
  566. }
  567. }
  568. }
  569. }
  570. }
  571. }
  572. }
  573. }
  574. }
  575. }
  576. }
  577. }
  578. }
  579. }
  580. }
  581. }
  582. }
  583. }
  584. }
  585. }
  586. }
  587. }
  588. }
  589. }
  590. }
  591. }
  592. }
  593. }
  594. }
  595. }
  596. }
  597. }
  598. }
  599. }
  600. }
  601. }
  602. }
  603. }
  604. }
  605. }
  606. }
  607. }
  608. }
  609. }
  610. }
  611. }
  612. }
  613. }
  614. }
  615. }
  616. }
  617. }
  618. }
  619. }
  620. }
  621. }
  622. }
  623. }
  624. }
  625. }
  626. }
  627. }
  628. }
  629. }
  630. }
  631. }
  632. }
  633. }
  634. }
  635. }
  636. }
  637. }
  638. }
  639. }
  640. }
  641. }
  642. }
  643. }
  644. }
  645. }
  646. }
  647. }
  648. }
  649. }
  650. }
  651. }
  652. }
  653. }
  654. }
  655. }
  656. }
  657. }
  658. }
  659. }
  660. }
  661. }
  662. }
  663. }
  664. }
  665. }
  666. }
  667. }
  668. }
  669. }
  670. }
  671. }
  672. }
  673. }
  674. }
  675. }
  676. }
  677. }
  678. }
  679. }
  680. }
  681. }
  682. }
  683. }
  684. }
  685. }
  686. }
  687. }
  688. }
  689. }
  690. }
  691. }
  692. }
  693. }
  694. }
  695. }
  696. }
  697. }
  698. }
  699. }
  700. }
  701. }
  702. }
  703. }
  704. }
  705. }
  706. }
  707. }
  708. }
  709. }
  710. }
  711. }
  712. }
  713. }
  714. }
  715. }
  716. }
  717. }
  718. }
  719. }
  720. }
  721. }
  722. }
  723. }
  724. }
  725. }
  726. }
  727. }
  728. }
  729. }
  730. }
  731. }
  732. }
  733. }
  734. }
  735. }
  736. }
  737. }
  738. }
  739. }
  740. }
  741. }
  742. }
  743. }
  744. }
  745. }
  746. }
  747. }
  748. }
  749. }
  750. }
  751. }
  752. }
  753. }
  754. }
  755. }
  756. }
  757. }
  758. }
  759. }
  760. }
  761. }
  762. }
  763. }
  764. }
  765. }
  766. }
  767. }
  768. }
  769. }
  770. }
  771. }
  772. }
  773. }
  774. }
  775. }
  776. }
  777. }
  778. }
  779. }
  780. }
  781. }
  782. }
  783. }
  784. }
  785. }
  786. }
  787. }
  788. }
  789. }
  790. }
  791. }
  792. }
  793. }
  794. }
  795. }
  796. }
  797. }
  798. }
  799. }
  800. }
  801. }
  802. }
  803. }
  804. }
  805. }
  806. }
  807. }
  808. }
  809. }
  810. }
  811. }
  812. }
  813. }
  814. }
  815. }
  816. }
  817. }
  818. }
  819. }
  820. }
  821. }
  822. }
  823. }
  824. }
  825. }
  826. }
  827. }
  828. }
  829. }
  830. }
  831. }
  832. }
  833. }
  834. }
  835. }
  836. }
  837. }
  838. }
  839. }
  840. }
  841. }
  842. else
  843. {
  844. fp=fopen("primes1.txt","w");
  845. }
  846. }
  847. printf("%d\n",prime);
  848. system("pause");
  849.     return 0;
  850. }
  851. //---------------------------------------------------------------------------
  852.  
  853. //---------------------------------------------------------------------------
Aug 14 '09
98 5918
JosAH
11,448 Expert 8TB
@scienceman88
Do your math: even if you store them in binary you still have to store 2^64/log(64) prime numbers which is 2^58 numbers. Each number thakes 8 bytes in binary so you need 2^61 bytes in total to store all the numbers. One giga bytes is 2^30 bytes so you need 2^31 gigabytes of storage to store all your numbers. In other words you need 2 giga giga bytes of storage. I wonder if so much storage exists on earth ... there are +- 2^160 atoms on earth but that includes you and me and elephants and tobacco and booze and tax forms and the earth itself and everything ...

kind regards,

Jos
Aug 16 '09 #51
I'm going lower now mainly because a 32 bit system can't go as high as I want.
I'm now going to 4-5 billion what's the math there because outside checking for errors I have a code that's possibly filling the 13-14 files I have the code making and that's less than 1 GB but I think I can get up past 2 billion if I make a few more files and I'm already over 1 billion
Aug 16 '09 #52
JosAH
11,448 Expert 8TB
@scienceman88
The math for 32 bit numbers is exactly the same as the math for 64 bit numbers: you'll find approximately 2^32/log(32) primes; each number takes 4 bytes (in binary) so you end up with 4*2^32/log(32) bytes of storage which is a bit less than 4 giga bytes.

kind regards,

Jos

ps. what do you want to do with those prime numbers?
Aug 16 '09 #53
find them or possibly use them to find mersenne primes which to be prime need p to be prime and take the form 2^p-1 the exponent being prime doesn't prove it prime but if it isn't it definitely isn't maybe I'll beat gimps lol using primes > 43 million I think
Aug 16 '09 #54
JosAH
11,448 Expert 8TB
@scienceman88
Google for the work of Lucas and Lehmer; these folks have done a lot w.r.t.primality finding. There are less than 50 Mersenne prime numbers found and you need a lot of memory, a lot of computing power and a lot more intelligent algorithms to be able to find a larger prime number than the latest (largest) Mersenne prime number found lately. My little algorithm most certainly is inadequate for the task.

kind regards,

Jos
Aug 16 '09 #55
Actually outside of finding out if the answer is prime your algorithm with work fine just have to fine a addition to figure out which (prime exponents of 2) -1 are actually prime. then my computer can figure it out till 2^4 billion -1 and a 64 bit could find all the way to (2 ^ 18 quintillion) -1
Aug 16 '09 #56
JosAH
11,448 Expert 8TB
@scienceman88
I do hope you realize that the gimps project has found a Mersenne prime of more than 10,000,000 digits; such numbers are far bigger than you can store in a long long data type. You need "big integer" packages for that.

It can be fun to play with the entire thing though ...

kind regards,

Jos
Aug 16 '09 #57
I'm not saying store the prime I'm saying find a pattern of the powers then write it in the notation (2^i)-1 into file so yes technically if we can find a pattern we can beat gimps.
Aug 16 '09 #58
and yes I knew it was over 12 million digits
Aug 16 '09 #59
The identity

shows that Mn can be prime only if n itself is prime—that is, the primality of n is necessary but not sufficient for Mn to be prime—which simplifies the search for Mersenne primes considerably
wikipedia so basically finding a prime like 13 means (2^13)-1 may be prime all we might need is a pattern to rule out prime exponents that don't allow the answer to be prime.
Aug 16 '09 #60
I may have print errors but if It's accurate 129704461, is prime so 2^129704461 could be prime if we had a part that figures out which exponents will result in a prime ( a.k.a primes but not all primes but more specific) then we can find all mersenne primes under (2^p) where p is prime and less than the limits of computing in C.
Aug 16 '09 #61
hence with enough room to store the last prime found in a notation like (2^p)-1 with a 64 bit system we could find mersenne primes up to (2^18 quintillion+)-1.
Aug 16 '09 #62
1,837,612,001 biggest prime before my files ran out of room by the looks of it pretty good but it would be cool to be able to use a pattern to figure out is (2^1,837,612,001)-1 prime
Aug 16 '09 #63
JosAH
11,448 Expert 8TB
@scienceman88
Yep, that's the difficult part and until now they have been determining whether or not that (huge) number is a prime number by 'classical' means, i.e. check all proper divisors etc. Despite the fact that these numbers have a very special structure (they are all 1s in binary notation) no results are known (yet?).

kind regards,

Jos
Aug 16 '09 #64
Okay I've got a weird idea normal primes are fun but what if I could come up with a pattern in one of the types that if accurate will land us in the record books( might need to write massive strings instead of numbers though). I think I see a pattern in the double mersenne primes(might have to use every computer in the world to confirm the next one as prime).
Aug 16 '09 #65
if you look at wikipedia the double mersenne primes go:

7, 127, 2147483647, 170141183460469231731687303715884105727
first all of them end in 7
next if you look at the table for mersenne primes they have:

p Mp
3 7
7 127
127 170141183…884105727

If I'm right in assuming the last Mp is the last in this series and this pattern continues( the pattern is Mp becomes the next p) then the next one in this sub series( or what ever you want to call it) is:

p
170141183460469231731687303715884105727

Mp
2^170,141,183,460,469,231,731,687,303,715,884,105, 727


if this is true it smashes all records as the biggest prime to date and biggest mersenne prime is 2^46 million and something this is 2^ 170 Undecillion and something.
Aug 16 '09 #66
JosAH
11,448 Expert 8TB
@scienceman88
If you find such a pattern you'll be world famous of course. If you're really interested in those Mersenne beasts read Eric Weisstein's Mathworld and google for Sloane's database of integer number series. They're interesting and fun.

kind regards.

Jos
Aug 16 '09 #67
yeah unfortunately they may have to reinvent computers and extend SI to fit it lol if I looked it up right it would take 2.12676479 × 10^37 bytes. and you thought I was crazy before lol. this would be over 21 tera x tera x terabytes lol.
Aug 16 '09 #68
JosAH
11,448 Expert 8TB
@scienceman88
Here's a last link because I have the feeling that you don't quite realize what you're up to.

kind regards,

Jos
Aug 17 '09 #69
Let n be an odd prime. The Mersenne number M(n) = 2n-1 is prime if and only if S(n-2) = 0 (mod M(n)) where S(0) = 4 and S(k+1) = S(k)2-2. We can add a few things in to do this testing and to try for a new record all we'd have to do is set the lower limit to the current record.
Aug 17 '09 #70
we know the primes that can be exponents if we further test them to check S(n-2) = 0 (mod M(n)) where S(0) = 4 and S(k+1) = S(k)2-2 if they fit that all it's a new record
Aug 17 '09 #71
JosAH
11,448 Expert 8TB
@scienceman88
What's your definition of S(k)?

kind regards,

Jos
Aug 17 '09 #72
That's the part I don't understand but if we can pull it off we may beat gimps take the 13 years streak and destroy it lol.
Aug 17 '09 #73
one thing I see is most of the prime exponents that don't work under 61 are of the form (2^6x-1)-1
Aug 17 '09 #74
is there a way I could define a data type that will fit all data under 171 undecillion ?
Aug 17 '09 #75
JosAH
11,448 Expert 8TB
@scienceman88
As I wrote before: you need a 'big integer' package; several are available, Google is your friend. About the definition of S(n): if it is what I think it is it's the sum of all proper divisors of n except n itself, e.g. S(6) == 1+2+3 = 6; S(28) == 1+2+4+7+14 == 28. When you see large primes you see perfect numbers around the corner (a perfect number equals the sum of its divisors, i.e. n == S(n)).

kind regards,

Jos
Aug 17 '09 #76
could a code be added to check those if so we would fit all needs for a mersenne prime tester and I know what else to change to find a new record faster.
Aug 17 '09 #77
found a full code for mersennes on rosettacode.org if it's true I can whip Gimps want to try ?
Aug 17 '09 #78
Expand|Select|Wrap|Line Numbers
  1. #include <math.h>
  2. #include <stdio.h>
  3. #include <limits.h>
  4. #pragma precision=log10l(ULLONG_MAX)/2
  5.  
  6. typedef enum { FALSE=0, TRUE=1 } BOOL;
  7.  
  8. BOOL is_prime( int p ){
  9.   if( p == 2 ) return TRUE;
  10.   else if( p <= 1 || p % 2 == 0 ) return FALSE;
  11.   else {
  12.     BOOL prime = TRUE;
  13.     const int to = sqrt(p);
  14.     int i;
  15.     for(i = 3; i <= to; i+=2)
  16.       if (!(prime = p % i))break;
  17.     return prime;
  18.   }
  19. }
  20.  
  21. BOOL is_mersenne_prime( int p ){
  22.   if( p == 2 ) return TRUE;
  23.   else {
  24.     const long long unsigned m_p = ( 1LLU << p ) - 1;
  25.     long long unsigned s = 4;
  26.     int i;
  27.     for (i = 3; i <= p; i++){
  28.       s = (s * s - 2) % m_p;
  29.     }
  30.     return s == 0;
  31.   }
  32. }
  33.  
  34. int main(int argc, char **argv){
  35.  
  36.   const int upb = log2l(ULLONG_MAX)/2;
  37.   int p;
  38.   printf(" Mersenne primes:\n");
  39.   for( p = 43112609; p <= upb; p += 1 ){
  40.     if( is_prime(p) && is_mersenne_prime(p) ){
  41.       printf (" M%u",p);
  42.     }
  43.   }
  44.   printf("\n");
  45.  
is an edited version of the code on rosettacode.org it gives me these warning can you help me solve them ?


[BCC32 Warning] File2.c(36): W8065 Call to function 'log2l' with no prototype
[BCC32 Warning] File2.c(45): W8070 Function should return a value
[ILINK32 Error] Error: Unresolved external '_log2l' referenced from C:\USERS\RODDY\DOCUMENTS\RAD STUDIO\PROJECTS\DEBUG\FILE2.OBJ
Aug 17 '09 #79
JosAH
11,448 Expert 8TB
@scienceman88
There is no prototype of function log2l( ... ) in scope anywhere; check your manual for which header file includes that prototype; #include that header file.

Your function main( ... ) is supposed to return an int. You are not returning anything at the end of that function. Insert 'return 0;' there.

Those old systems want you to explicitly link in the math library; add the '-lm' flag on the linker's command line.

kind regards,

Jos
Aug 17 '09 #80
@JosAH
lm flag ? god I suck at C
even I figured the return part
I go by the standard headers and i have no idea what one would have it maybe it's a C99 complex.h function.
Aug 17 '09 #81
Think if my search is right it's in math.h but I could be wrong http://www.codecogs.com/reference/c/...hp?alias=log2l
Aug 17 '09 #82
I didn't even know there was a search.h see I learn things too much so I forget most things I think I love learning though so I'll have to adapt
Aug 17 '09 #83
JosAH
11,448 Expert 8TB
@scienceman88
I don't know what you mean by 'Im flag ?'. The log2l( ... ) function most likely is a Borland function so they must have a header file available for it and, more important, a library that contains the definition of it. It is not a C99 thing.

kind regards,

Jos
Aug 17 '09 #84
by what I've found it should be in math.h so I have no idea why it doesn't work I know what its supposed to do but I don't know how I can do it
Aug 17 '09 #85
JosAH
11,448 Expert 8TB
@scienceman88
Check your math.h file and see if you can find a prototype of that function in there.

kind regards,

Jos
Aug 17 '09 #86
Works with: gcc version 4.1.2 20070925 (Red Hat 4.1.2-27) Works with: C99 Compiler options: gcc -std=c99 -lm Lucas-Lehmer_test.c -o Lucas-Lehmer_test
#include <math.h>
#include <stdio.h>
#include <limits.h>
#pragma precision=log10l(ULLONG_MAX)/2

typedef enum { FALSE=0, TRUE=1 } BOOL;

BOOL is_prime( int p ){
if( p == 2 ) return TRUE;
else if( p <= 1 || p % 2 == 0 ) return FALSE;
else {
BOOL prime = TRUE;
const int to = sqrt(p);
int i;
for(i = 3; i <= to; i+=2)
if (!(prime = p % i))break;
return prime;
}
}

BOOL is_mersenne_prime( int p ){
if( p == 2 ) return TRUE;
else {
const long long unsigned m_p = ( 1LLU << p ) - 1;
long long unsigned s = 4;
int i;
for (i = 3; i <= p; i++){
s = (s * s - 2) % m_p;
}
return s == 0;
}
}

int main(int argc, char **argv){

const int upb = log2l(ULLONG_MAX)/2;
int p;
printf(" Mersenne primes:\n");
for( p = 2; p <= upb; p += 1 ){
if( is_prime(p) && is_mersenne_prime(p) ){
printf (" M%u",p);
}
}
printf("\n");
}
Output:
Mersenne primes:
M2 M3 M5 M7 M13 M17 M19 M31
Aug 17 '09 #87
JosAH
11,448 Expert 8TB
@scienceman88
So it works for small values of p; now go for the really big ones. btw, please use those code tags around your code for readability reasons.

kind regards,

Jos
Aug 17 '09 #88
I can't get it to work for any
Aug 17 '09 #89
JosAH
11,448 Expert 8TB
@scienceman88
You have to be more exact: first you write that the output happened to be correct and showed it to us and now you're writing that it doesn't work at all. I you want help you have to help us understand you. btw, the probability of a thread ending successfully is inversely proportional to the length of the thread.

kind regards,

Jos
Aug 17 '09 #90
no I'm talking the code from rosetta doesn't seem to work at all not yours
Aug 17 '09 #91
JosAH
11,448 Expert 8TB
@scienceman88
Sprinkle a lot if print( ... ) calls all over the place and see what happens; printf( ...) is the poor man's debugger.

kind regards,

Jos
Aug 17 '09 #92
the only error I got with the original is with log2l but I can't even seem to get log2 to work period.
Aug 17 '09 #93
@JosAH
so basically I'm poor ?
Aug 17 '09 #94
JosAH
11,448 Expert 8TB
@scienceman88
I don't know but using printf( ... ) is an easy way to debug your code; it's just a matter of speech: the poor man's debugger.

kind regards,

Jos
Aug 17 '09 #95
I think I see how but I'm busy arguing at mersenneforums.org right now lol
Aug 17 '09 #96
JosAH
11,448 Expert 8TB
@scienceman88
Don't crosspost, you'll be spoiling people's time: they'll answer questions that are probably answered before without knowing it.

kind regards,

Jos

ps. I consider this thread closed to avoid duplication of subjects and answers.
Aug 18 '09 #97
r035198x
13,262 8TB
Sneaking in a subscription before the thread gets closed.
Aug 19 '09 #98
JosAH
11,448 Expert 8TB
@r035198x
And *bang* the door is closed. If the OP wants to ask other (or related) questions I suggest he'd open up a new thread.

kind regards,

Jos
Aug 19 '09 #99

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Philp Smith | last post: by
32 posts views Thread by someone else | last post: by
19 posts views Thread by gk245 | last post: by
1 post views Thread by Clint Boaz | last post: by
7 posts views Thread by jmDesktop | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.