Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

โปรแกรมหาเลข Cullen ใน C++


ในบทช่วยสอนนี้ เราจะพูดถึงโปรแกรมหาเลข Cullen

เราจะได้รับจำนวนเต็ม งานคือหาเลข Cullen ณ ตำแหน่งนั้นโดยใช้สูตร:

2^n * n + 1

ตัวอย่างโค้ด

#include <bits/stdc++.h>
using namespace std;

unsigned get_cullen(unsigned n) {
    return (1 << n) * n + 1;
}

int main() {
    int n = 2;
    cout << get_cullen(n);
    return 0;
}

เอาต์พุต

9