Hdoj 2802 F (N)

Source: Internet
Author: User


Follow link 4018

F (N)Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 3542 Accepted Submission (s): 1219


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 Input
1230

Sample Output
1720

Sourcehdu 2009-4 Programming Contest


/* ***********************************************author        : ckbosscreated time  : Sunday December 14, 2014 12:29 33 sec File Name     : hdoj2802.cpp************************************************ */#include <iostream># Include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cstdlib > #include <vector> #include <queue> #include <set> #include <map> #include <cmath> using namespace Std;const int mod=2009;int f[5000];int Get (int x) {int part1= ((x*x)%mod*x)%mod;int y=x-1;int part2= ((y*y) %mod*y)%mod;return ((f[x-2]+part1)%mod+mod-part2)%mod;} int main () {    //freopen ("In.txt", "R", stdin);    Freopen ("OUT.txt", "w", stdout); int n;f[1]=1; f[2]=7;for (int i=3;i<=4018;i++) f[i]=get (i), while (scanf ("%d", &n)!=eof&&n) {n=n%4018;if (n==0) puts (" 0 "); else printf ("%d\n ", F[n]);}    return 0;}



Hdoj 2802 F (N)

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.