示例#1
0
int main(){
	size_t sum = 0;
	for(size_t i = 0; i < MAX_ITERATIONS; i++){
		// If the number is a multiple of 3, 5, or both, add it to the sum.
		if(isMultipleOf(3, i) || isMultipleOf(5, i)){
			sum += i;
		}
	}
	std::cout << "The sum of all the natural numbers below one thousand that are multiples of 3 or 5" << std::endl;
	std::cout << "Sum: " << sum << std::endl;
	return 0;
}
示例#2
0
void findSumOfMultiples(int multiple1, int multiple2, int lessThan)
{
    int i = 0;
    
    while (i < lessThan) {
        if (!isMultipleOf(i, multiple1) || !isMultipleOf(i, multiple2)) {
            sumOfMultiples += i;
        } 
        i++;
    }

}
//-----------------------------------------------------------------------------------------------------------------------
//      DE-/INITIALIZE
//-----------------------------------------------------------------------------------------------------------------------
void OctreeBrickPoolManagerDisk::initialize(size_t brickMemorySizeInByte) throw (VoreenException)
{
    OctreeBrickPoolManagerBase::initialize(brickMemorySizeInByte);

    // round max buffer size down to next multiple of brick memory size
    if (maxBufferSizeBytes_ < getBrickMemorySizeInByte())
        throw VoreenException("Max brick buffer size is smaller than the memory size of a single brick "
        "[" + itos(maxBufferSizeBytes_) + " bytes < " + itos(getBrickMemorySizeInByte()) + " bytes]");
    singleBufferSizeBytes_ = maxBufferSizeBytes_;
    if (!isMultipleOf(singleBufferSizeBytes_, getBrickMemorySizeInByte()))
        singleBufferSizeBytes_ = tgt::ifloor((float)maxBufferSizeBytes_ / (float)getBrickMemorySizeInByte()) * getBrickMemorySizeInByte();

    numBrickSlotsPerBuffer_ = singleBufferSizeBytes_ / brickMemorySizeInByte;

    if (!tgt::FileSystem::dirExists(brickPoolPath_))
        throw VoreenException("Brick pool path does not exist: " + brickPoolPath_);

    // check ram limit vs. buffer size: at least 2 buffers have to fit into the ram
    if (2*singleBufferSizeBytes_ > ramLimitInBytes_)
        throw VoreenException("RAM memory limit is smaller than two times the size of a buffer. At least two buffer files have to fit in the RAM. "
            "[" + itos(ramLimitInBytes_) + " bytes < 2*" + itos(singleBufferSizeBytes_) + " bytes]");

    // define max value
    maxNumBuffersInRAM_ = ramLimitInBytes_/singleBufferSizeBytes_;
}