首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

! Really Strange !

2013-09-12 
!! Really Strange !!http://acm.hust.edu.cn/vjudge/contest/view.action?cid31329#problem/Bf[ 0 ] 1

!! Really Strange !!

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=31329#problem/B

f[ 0 ] = 1 , f[ n ] = f[ n - 1 ] + 2 * (n - 1 ),化简得f[n]=n^2 - n + 2 ;

import java.math.BigInteger;import java.util.Scanner;public class Main{public static void main(String[] args ){Scanner cin = new Scanner(System.in);while( cin.hasNext()){BigInteger n = cin.nextBigInteger();if( n.equals(BigInteger.valueOf(0))){System.out.println("1");}else{n = n.multiply(n).add(n.negate()).add(BigInteger.valueOf(2));System.out.println(n);}}}}


热点排行