Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <ctime>
- #define N1 100000ULL
- #define N2 1000000ULL
- #define TABLESIZE 1610612736
- #define TABLENAME "table_1610612736"
- int main(){
- std::ofstream file("output.txt");
- char *table = new char[TABLESIZE];
- for(int aa=0; aa<TABLESIZE; aa++) table[aa] = -1;
- table[0] = 1;
- table[4] = 2;
- table[16] = 3;
- unsigned long long int s=0,m=0,l=0,n,x=0;
- //make/load the table
- FILE *f;
- f = fopen(TABLENAME, "r");
- if(f){
- fread(table, sizeof(char), TABLESIZE, f);
- }
- else{
- for(unsigned long long int aa=1; aa<=TABLESIZE; aa++){
- if(aa%1000000==0) std::cout << aa << "\n";
- n=aa;
- while(n > TABLESIZE || table[n-1] == -1){
- if(n%2==0) n/=2;
- else n=(3*n-1)/2;
- }
- table[aa-1] = table[n-1];
- }
- f = fopen(TABLENAME, "w+");
- fputs(table, f);
- }
- fclose(f);
- //do the iterations
- time_t t = clock();
- for(unsigned long long int aa=0; aa<N1; aa++){
- for(unsigned long long int ab=1; ab<=N2; ab++){
- n=x+ab;
- while(n>TABLESIZE){
- if(n%2==0) n/=2;
- else n=(3*n-1)/2;
- }
- if(table[n-1]==1) s++;
- else if(table[n-1]==2) m++;
- else if(table[n-1]==3) l++;
- }
- x = N2*(aa+1);
- float totaltime = (float)(clock()-t)/60000;
- float timeperloop = totaltime/(aa+1);
- float remaining = timeperloop*(N1-aa-1);
- std::cout << x << "\telapsed: " << totaltime << "m\tremaining: " << remaining << "m\n";
- file << x << " " << s << " " << m << " " << l << "\n";
- }
- std::cout << s << " " << m << " " << l;
- file.flush();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment