程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> SGU - 135 - Drawing Lines (簡單數學!)

SGU - 135 - Drawing Lines (簡單數學!)

編輯:C++入門知識

SGU - 135 - Drawing Lines (簡單數學!)


SGU - 135 Drawing Lines Time Limit: 250MS Memory Limit: 4096KB 64bit IO Format: %I64d & %I64u

Submit Status

Description

Little Johnny likes to draw a lot. A few days ago he painted lots of straight lines on his sheet of paper. Then he counted in how many zones the sheet of paper was split by these lines. He noticed that this number is not always the same. For instance, if he draws 2 lines, the sheet of paper could be split into 4, 3 or even 2 (if the lines are identical) zones. Since he is a very curious kid, he would like to know which is the maximum number of zones into which he can split the sheet of paper, if he draws N lines. The sheet of paper is to be considered a very large (=infinite) rectangle.

Input

The input file will contain an integer number: N (0<=N<=65535).

Output

You should output one integer: the maximum number of zones into which the sheet of paper can be split if Johnny draws N lines.

Sample Input #1

0

Sample Output #1

1

Sample Input #2

1

Sample Output #2

2

Author : Mugurel Ionut Andreica Resource : SSU::Online Contester Fall Contest #2 Date : Fall 2002

Source



也是一個數學題,找規律的。。


規律:1,2,4,7,11,16...... a(n) = n*(n+1)/2+1;(n從0開始)


AC代碼:


#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	printf("%d\n", (int)((long long)n*(n+1)/2+1)); 
	return 0;
} 


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved