Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2603105
  • 博文数量: 877
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 5920
  • 用 户 组: 普通用户
  • 注册时间: 2013-12-05 12:25
个人简介

技术的乐趣在于分享,欢迎多多交流,多多沟通。

文章分类

全部博文(877)

文章存档

2021年(2)

2016年(20)

2015年(471)

2014年(358)

2013年(26)

分类: 高性能计算

2015-05-26 19:45:09

受大牛指点先分享各种小算法,勿喷。

// 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,
阅读(859) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~