Пример #1
0
Файл: main.c Проект: goma/goma
void
echo_command_line( int argc, char *argv[], char *echo_file)
{
	int istr=0;
	char echo_string[MAX_CHAR_IN_INPUT]="\0";
	time_t start_time;
	char *time_string;
	
	start_time = time (NULL);
	time_string = asctime( localtime(&start_time) );
	
	SPF(echo_string,"Command line :");
	
	while( istr < argc )
	{
		SPF(endofstring(echo_string)," %s", argv[istr]);
		istr++;
	}
	
	ECHO(echo_string, echo_file);
	
	SPF(echo_string,"Run Time : %s",  time_string);
		
	SPF(endofstring(echo_string),"Version : %s", GOMA_VERSION);
	
	ECHO(echo_string,echo_file);
	
}
Пример #2
0
/*
 * Modified Sieve of Eratosthenes that runs in O(n) time. Algorithm requires 
 * O(n) space too but this can be used to store the primes which are needed
 * later.
 */
std::vector<int> modified_sieve(int input) {
    std::vector<bool> isprime(input, true);
    std::vector<int> primes;
    std::vector<int> SPF(input);

    isprime[0] = isprime[1] = false;
    for(int i = 2; i < input; ++i) {
        if(isprime[i]) {
            primes.push_back(i);
            SPF[i] = i;
        }
        //remove all multiples of i*prime[j] and set SPF[i*prime[j]] = prime[j]
        for(int j = 0; j < primes.size() && i*primes[j] < input && 
            primes[j] <= SPF[i]; ++j) {
            isprime[i*primes[j]] = false;
            SPF[i*primes[j]] = primes[j];
        }
    }
    return primes;
}