#UVa:913-Joana and the Odd Numbers

首先先找到行數跟那行有幾個值的關係而求得行數,再來透過行數找出最後一個值,接著就求出答案了=D

C++(0.016)

/*******************************************************/
/* UVa 913 Joana and the Odd Numbers                   */
/* Author: LanyiKnight [at] knightzone.org             */
/* Version: 2011/11/29                                 */
/*******************************************************/
#include<iostream>
#include<cstdio>
using namespace std;

int main(){
  long long N, sum;
  while( scanf( "%lld", &N ) != EOF ){
    sum = (N+1)/2; // row number;
    sum = sum*sum*2-1; // the last number of that row;
    sum = 3*sum - 6;
    printf( "%lld\n", sum );
  }
  return 0;
}

沒有迴響

本文還沒有迴響,快來搶頭香!

發表迴響