在 C++ 中找出数列 9、45、243、1377… 的第 N 项
在此问题中,我们给定一个整数值 N。我们的任务是找出数列的第 n 项 −
9、45、243、1377、8019、…
我们举一个例子来理解这个问题,
Input : N = 4 Output : 1377
求解方案
根据观察技术找出第 N 项是该问题的简单解法。通过观察该数列,我们可以 формулировать(俄语拼写)如下 −
(11 + 21)*31 + (12 + 22)*32 + (13 + 23)*33 … + (1n + 2n)*3n
实例
演示我们解决方案的程序
#include <iostream>
#include <math.h>
using namespace std;
long findNthTermSeries(int n){
return ( ( (pow(1, n) + pow(2, n)) )*pow(3, n) );
}
int main(){
int n = 4;
cout<<n<<"th term of the series is "<<findNthTermSeries(n);
return 0;
}输出
4th term of the series is 1377
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP