受大牛指点先分享各种小算法,勿喷。
// ConsoleApplication3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
//int _tmain(int argc, _TCHAR* argv[])
//{
// return 0;
//}
//
//
using namespace std;
typedef unsigned int ULONG;
ULONG fun(ULONG value, ULONG num);
int main(void)
{
ULONG n = 1000;
long long sum = 0;
//sum = 3 * a * (a + 1) / 2 + 5 * b * (b + 1) / 2 - 15 * c * (c + 1) / 2;
sum = fun(3, n) + fun(5, n) - fun(15, n);
cout << sum << endl;
return 0;
}
ULONG fun(ULONG value, ULONG upper)
{
upper -= 1;
int foo = upper / value;
return value * foo * (foo + 1) / 2;
}
//1, 2, 3, 5, 8, 13, 21, 34, 55, 89,
阅读(915) | 评论(0) | 转发(0) |