Calculate S(n)

Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9102    Accepted Submission(s): 3325

Problem Description
Calculate S(n).

S(n)=13+23 +33 +......+n3 .

 
Input
Each line will contain one integer N(1 < n < 1000000000). Process to end of file.
 
Output
For each case, output the last four dights of S(N) in one line.
 
Sample Input
1
2
 
Sample Output
0001
0009
 
Author
天邪
方法一:全算出来。
思路:当n>10000以后,只用关心后四位的数字即可。
知识点:模算术公式:(a+b)%n = ((a%n)+(b%n))%n
          (a-b)%n = ((a%n)-(b%n))%n
            a*b%n = (a%n)*(b%n)%n
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
using namespace std; const int INF=0x3f3f3f3f;
const double eps=1e-;
const double PI=acos(-1.0);
#define maxn 10005
long long a[maxn];
int main()
{
long long sum = ;
for(int i = ; i <= ; i++)
{
sum += (i%*i%*i%)%;
sum = sum %;
a[i] = sum;
}
int n;
while(~scanf("%d", &n))
{
if(n <= )
{
printf("%04d\n",a[n]);
}
else
{
int t = n/;
int k = n - t*;
long long sum1 = ;
sum1 = ((t%)*(a[]%))% + a[k]%;
printf("%04d\n",sum1); }
}
return ;
}

方法二:直接公式

#include <stdio.h>
int main()
{
__int64 n,sum;
while (scanf("%I64d",&n)!=EOF)
{
sum=;
n=n%;
sum=(n*(n+)/)*(n*(n+)/)%;// 为了防止计算sum中乘法溢出将n=n%10000;因为要求得后4位数。
printf("%04I64d\n",sum);
}
return ;
}

HDU2114 Calculate S(n) (取模算术)的更多相关文章

  1. Gym100947E || codeforces 559c 组合数取模

    E - Qwerty78 Trip Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

  2. hoj3152-Dice 等比数列求和取模

    http://acm.hit.edu.cn/hoj/problem/view?id=3152 Dice My Tags (Edit) Source : Time limit : sec Memory ...

  3. Codeforces Round #260 (Div. 2) A B C 水 找规律(大数对小数取模) dp

    A. Laptops time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  4. The 2018 ACM-ICPC China JiangSu Provincial Programming Contest快速幂取模及求逆元

    题目来源 The 2018 ACM-ICPC China JiangSu Provincial Programming Contest 35.4% 1000ms 65536K Persona5 Per ...

  5. UVA-10929-You can say 11(秦九昭算法+同余与模算术)

    原题链接 1000位大数取余: 秦九昭算法+同余与模算术: 1314 = (((1)*10+3)*10+1)*10+4 ( a + b ) % n = ( ( a % n ) + ( b % n ) ...

  6. hdu-5666 Segment(俄罗斯乘法or大数乘法取模)

    题目链接: Segment Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) P ...

  7. 题解报告:hdu 1212 Big Number(大数取模+同余定理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 Problem Description As we know, Big Number is al ...

  8. E - A^B mod C (大数乘方取模)

    Description Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,B,C<2^63) ...

  9. cf 450b 矩阵快速幂(数论取模 一大坑点啊)

    Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...

随机推荐

  1. 算法中的增长率(Rate of Growth)是什么意思?

    一个函数或算法的代码块花费的时间随输入增长的速率称为增长率. 假设你去买一辆小车和一辆自行车.如果你朋友刚好看到,问你在买什么,我们一般都会说:买小车.因为买小车比买自行车花费高多了. [总花费=小车 ...

  2. python socket之tcp服务器与客户端demo

    python socket之tcp服务器与客户端demo 作者:vpoet mails:vpoet_sir@163.com server: # -*- coding: cp936 -*- ''' 建立 ...

  3. wget命令1(转载)

    Linux系统中的wget是一个下载文件的工具,它用在命令行下.对于Linux用户是必不可少的工具,我们经常要下载一些软件或从远程服务器恢复备份到本地服务器.wget支持HTTP,HTTPS和FTP协 ...

  4. 表格td标签在不添加多余标签的情况下实现文本内容单行显示,多余部分省略号表示的方法

    #table { table-layout: fixed; } .content { white-space: nowrap; text-overflow: ellipsis; -o-text-ove ...

  5. 1 游戏逻辑架构,Cocos2d-x游戏项目创建,HelloWorld项目创建,HelloWorld程序分析,(CCApplicationProtocol,CCApplication,AppDeleg

     1 游戏逻辑架构 具体介绍 A 一个导演同一时间仅仅能执行一个场景,场景其中,能够同一时候载入多个层,一个层能够可载多个精灵.层中亦能够加层. B  场景切换 sceneàaddChild(la ...

  6. Zjnu Stadium(hdu3047带权并查集)

    题意:一个300列的无限行的循环场地,a b d代表a,b顺时针相距d的距离,现在给你一些距离,判断是否有冲突,如果有冲突计算冲突的次数 思路:带权并查集 a,b的距离等于b到根节点的距离 - a到根 ...

  7. UNIX下解压缩文件

    用法示例以Sun Solaris (其他unix如linux.aix大体相同)为例=========================================================== ...

  8. SDP协议

    会话描述协议(SDP)为会话通知.会话邀请和其它形式的多媒体会话初始化等目的提供了多媒体会话描述.它只是用来描述,而不是一种传输协议.举例,在SIP协议的Message Header的Content- ...

  9. Notepad++编译c++时使用的代码

    cmd /c "g++ -o $(CURRENT_DIRECTORY)\$(NAME_PART).exe $(FULL_CURRENT_PATH)" 出现控制台.  NppExec ...

  10. (原)matlab中使用mex编译多个cpp文件

    以前一直是mex一个文件.刚才需要编译多个文件(如a.cpp调用b.cpp的函数,b.cpp调用c.cpp的函数).如果只是mex a.cpp,提示函数找不到函数. 突然想到mex c.cpp b.c ...