1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【ABC234】A - Weird Function をC++で解説

Posted at

はじめに

 皆さんこんにちは! 競プロの問題の理解を深めるために解説記事を書いていこうと思います!今回は ABC234 A, B, C です!
気に入っていただけたらLGTMして頂けるとうれしいです!
何かあればコメントTwitterからお願いいたします!

A - Weird Function

問題の詳細は上の見出しからいけます.
Difficulty : 7

問題概要

関数$f$を$f(x) = x^2 + 2x + 3$としたときの
$f(f(f(t) + t) + f(f(t)))$を求めよ.

制約

 $0 \leq t \leq 10 $

考察

ポイント

$f(x)$を関数で定義しよう

解説

求める関数$f(x)$をプログラミングにおける関数にして出力しましょう.

実装

値が大きくなるので関数の戻り値はlong long型を用いましょう.

正解コード

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

 //f(x)の関数
long long f(int t){
    return t * t + 2 * t + 3;
}

int main()
{
    //入力
    long long t;
    cin >> t;
    //出力
    cout << f(f(f(t) + t) + f(f(t))) << endl;

}

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?