Hdoj 2802 F (N) "Recursive law"

Source: Internet
Author: User

F (N)

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4078 Accepted Submission (s): 1432


Problem Description
Giving the N, can you tell me the answer of F (N)?

Inputeach test case contains a single integer N (1<=n<=10^9). The input is terminated by a set starting with N = 0. This set should is processed.

Outputfor each test case, output in a line the value of the F (N)%2009.

Sample Input1230

Sample Output1720 General This lets according to the formula to find the corresponding item is worth the law (there is a loop, the loop of the problem is 4018 (note that this has a cyclic law is to let you output the corresponding item to a number after the problem)) can first hit the table to write a finite number of results, and then observe the law
#include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> #define LL Long Long#define MAX 10010using namespace std; LL S[max]; LL p[max];void Biao () {int i,j;s[1]=p[1]=1;s[2]=p[2]=7;for (i=3;i<=4020;i++) {S[i]=s[i-2]+pow (i,3)-pow ((i-1), 3);p [I]=s[i]%2009;}} int main () {int N,m,i,j;biao (), while (scanf ("%d", &n), N) {printf ("%lld\n", p[n%4018]);} return 0;}

  

Hdoj 2802 F (N) "Recursive law"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.