473,903 Members | 4,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

loop for finding possible odd divisors

85 New Member
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 6235
hsheboul
14 New Member
@donbock
You are right Don, I was not that precise in writing the pseudo code.

@donbock
Ah, how large is that N, and how to find some info related to that N!

Two things can decide upon N:
(don't forget the problem is undecidable)
1. the hardware capabilities,
2. the time available

Check out
http://primes.utm.edu/largest.html
Aug 15 '09 #11
JosAH
11,448 Recognized Expert MVP
@scienceman88
Tadaa! Lines #10 and #11 are the loop you asked for. All primes (except 2 and 3) are a multiple of 6 plus or minus 1; that's exactly what that loop tests: i.e. if a number evenly divides by 6*x +- 1 it can never be a prime number.

kind regards,

Jos
Aug 15 '09 #12
Banfa
9,065 Recognized Expert Moderator Expert
@JosAH
[slightly off topic silly and pedantic mode]Strictly speaking if a number is not a prime number it can "never" be a prime number there time is not a factor controlling if a number is prime or not :D
[/slightly off topic silly and pedantic mode]

Err Sorry
Aug 15 '09 #13
JosAH
11,448 Recognized Expert MVP
@Banfa
You're wrong: there can be temporary prime numbers; e.g. they can be prime during the weekends or after 11:00pm or so. My hypothesis is that every number can be a temporary prime number but we don't know when it'll be prime and maybe they're also shy so they won't show their primeness when they're prime ...

kind regards,

Jos ;-)
Aug 15 '09 #14
scienceman88
85 New Member
Okay
1)I barely understood your code jos
2)I tried to insert it to file instead and I couldn't get it to work.
3)N= max for unsigned long long integers or about 18,446,744,073, 709,551,615
4) you can use prime numbers before to calculate the next one it follows the sieve of eratosthenes( i know the sieve of atkin is faster but I don't understand it) and those sieves are the only known ways to find all primes except maybe primality testing each number
Aug 15 '09 #15
scienceman88
85 New Member
5)I want to use ftell and f seek to keep the files small enough to read in dos 4GB(a little less for possible overflow) I think so
Aug 15 '09 #16
JosAH
11,448 Recognized Expert MVP
@scienceman88
1) Yes I know, I've always been a smartypants; my mother dropped me on my head when I was a baby ;-)

2) My code simply prints the primes to stdout; it doesn't take rocket science to print the primes to elsewehere.

3) I take your word for it; no, I won't I'll check it ... yep, you're right.

4) both are similar algorithms in disguise: sieves filter out equal factors for all numbers while my primality check filtes out all factors per number. It doesn't need that huge array of bits to keep track of all the numbers.

kind regards.

Jos
Aug 15 '09 #17
JosAH
11,448 Recognized Expert MVP
@scienceman88
Just keep track on the number of bytes written already; when it exceeds a certain threshold, close the file and quit the process. There's no need for ftell() or fseek().

kind regards,

Jos
Aug 15 '09 #18
scienceman88
85 New Member
@JosAH
unless I watch it manually close it and expect it to say next file there is as i know it won't all get into one file of 4 gb or less
Aug 15 '09 #19
scienceman88
85 New Member
I can't get it to print to file never worked in more than one function before so unless i have to declare the pointer globally but change it internally I'll never be able to use the code
Aug 15 '09 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3232
by: Philp Smith | last post by:
Hi Does anyone have suggested code for a compact, efficient, elegant, most of all pythonic routine to produce a list of all the proper divisors of an integer (given a list of prime factors/powers)
6
3926
by: Dave | last post by:
I have to automate a process that assigns sales leads to sales people. For example: Every day we buy a list of sales leads, it ranges in size from 50 - 100 records. We have a team of sales people that also can range from 5 - 8 people. I need to take the new records and divide them evenly among the sales people.
32
5134
by: someone else | last post by:
hi all I'm a newbie to this group. my apologies if I break any rules. I've wrote a simple program to find the first 1,000,000 primes, and to find all primes within any range (up to 200 * 10^12) it's pretty efficient, it took 15 minutes to compute the first 1,000,000 primes.
19
4470
by: gk245 | last post by:
Trying to write a program that will figure out if a number is perfect or not. Here is my logic: 1) Read in the number 2) Split it up (number - 1) 3) Put all the split up numbers into an array 4) Figure out if the original number is evenly divisible by any of the numbers in the array.
29
5129
by: garyusenet | last post by:
I'm trying to investigate the maximum size of different variable types. I'm using INT as my starting variable for exploration. I know that the maximum number that the int variable can take is: 65,535. But i'm trying to write a program to test this, assuming I didn't know this number in advance. I came up with the following but have two questions. Maybe someone can help? using System; using System.Collections.Generic; using System.Text;
2
2019
by: jknox13 | last post by:
Hi, I have to find the divisors of all numbers less than a number inputed by the user and state if a number is prime if no divisors. I have this code so far, but I'm getting the wrong output and not sure how to list all the numbers less than the input number. Please help. #include <iostream> using namespace std; // function declarations // ------------------- bool isPrime (int);
1
1779
by: Clint Boaz | last post by:
I am just trying to learn C++ and having a problem trying to write a program that finds the sum of the proper divisors of a given integer n and returns whether n is deficient, perfect or abundant.
3
2783
by: jimix | last post by:
I have written the program for factors of #'s 1-50 but the factors print out below the number being factored. I can't figure out how to make it all on the same line. i.e. (now) divisors of 25 are 1 5 25 (need) divisors of 25 are 1, 5, 25. here is my code; #include <stdio.h>
7
1968
by: jmDesktop | last post by:
From the Python.org tutorial: .... for x in range(2, n): .... if n % x == 0: .... print n, 'equals', x, '*', n/x .... break .... else: .... # loop fell through without finding a factor .... print n, 'is a prime number' ....
0
9852
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10882
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10989
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9692
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5899
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6099
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3327
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.