HDU2114 Calculate S(n) (取模算术)
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
S(n)=13+23 +33 +......+n3 .
2
0009
#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) (取模算术)的更多相关文章
- Gym100947E || codeforces 559c 组合数取模
E - Qwerty78 Trip Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u S ...
- hoj3152-Dice 等比数列求和取模
http://acm.hit.edu.cn/hoj/problem/view?id=3152 Dice My Tags (Edit) Source : Time limit : sec Memory ...
- 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 ...
- The 2018 ACM-ICPC China JiangSu Provincial Programming Contest快速幂取模及求逆元
题目来源 The 2018 ACM-ICPC China JiangSu Provincial Programming Contest 35.4% 1000ms 65536K Persona5 Per ...
- UVA-10929-You can say 11(秦九昭算法+同余与模算术)
原题链接 1000位大数取余: 秦九昭算法+同余与模算术: 1314 = (((1)*10+3)*10+1)*10+4 ( a + b ) % n = ( ( a % n ) + ( b % n ) ...
- hdu-5666 Segment(俄罗斯乘法or大数乘法取模)
题目链接: Segment Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) P ...
- 题解报告:hdu 1212 Big Number(大数取模+同余定理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 Problem Description As we know, Big Number is al ...
- 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) ...
- cf 450b 矩阵快速幂(数论取模 一大坑点啊)
Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...
随机推荐
- UESTC_邱老师选妹子 2015 UESTC Training for Dynamic Programming<Problem H>
H - 邱老师选妹子 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- Valid Palindrome 解答
Question Given a string, determine if it is a palindrome, considering only alphanumeric characters a ...
- ZOJ2913Bus Pass(BFS+set)
Bus Pass Time Limit: 5 Seconds Memory Limit: 32768 KB You travel a lot by bus and the costs of ...
- hihoCoder #1234 : Fractal(数学简单题)
时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 This is the logo of PKUACM 2016. More specifically, the logo i ...
- JS给元素循环添加事件的问题
<ul> <li>男</li> <li>女</li> <li>老</li> <li>少</li&g ...
- JAX-RS开发 hello world
1.建立maven webapp工程aty-rest. 2. 在pom文件增加spring框架.jax-rs接口.CXF实现 <dependency> <groupId>jav ...
- Reverse Words in a String (JAVA)
Given an input string, reverse the string word by word. For example,Given s = "the sky is blue& ...
- Android图片下载到本地,系统图库不显示
可能大家都知道我们下载图片到Android手机的时候,然后调用系统图库打开图片,提示"找不到指定项". 那是因为我们插入的图片还没有更新的缘故,所以只要将图片插入系统图库,之后发条 ...
- HTTP状态码搜集
一.1xx消息 这一类型的状态码,代表请求已经接受,需要继续处理. 这类响应是临时响应,只包含状态行和某些可选的响应头信息,并以空行结束. 由于HTTP/1.0协议中没有定义任何1xx状态码,所以除非 ...
- java 短信发送例子 tdy
import java.io.IOException; import java.util.logging.Level;import java.util.logging.Logger;import or ...