1143 -- 函数解析式

本文介绍了一个二次函数问题:已知f(x+1)=f(x)+2x且f(0)=1,通过递推公式求解特定x值时的函数值。提供了一种使用数组存储中间结果的方法来解决此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

函数解析式

Time Limit:1000MS  Memory Limit:65536K
Total Submit:167 Accepted:128

Description

二次函数f(x)满足 f(x+1)=f(x)+2x 且f(0)=1。

Input

第一行有一个整数N表示N组测试数据。
接下来有N行,且每行都有一个整数x(0 < x < 10000)。

Output

求每组测试数据中f(x)的值。

Sample Input

2
1
2

Sample Output

1
3

Hint

ahstu@icpc2014

Source

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    namespace AK1143 {
        class Program {
            static void Main(string[] args) {
                int[] a = new int[10005];
                a[0] = 1;
                for (int i = 1; i < 10001; i++)
                    a[i] = a[i - 1] + 2 * (i - 1);
                int n = int.Parse(Console.ReadLine());
                while (n-- > 0) {
                    int x = int.Parse(Console.ReadLine());
                    Console.WriteLine(a[x]);
                }
            }
        }
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值