博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
GCC 超时
阅读量:4035 次
发布时间:2019-05-24

本文共 1452 字,大约阅读时间需要 4 分钟。

1、

2、GCC

Time Limit: 1000MS    Memory limit: 65536K

题目描述

The GNU Compiler Collection (usually shortened to GCC) is a compiler system produced by the GNU Project supporting various programming languages.  But it doesn’t contains the math operator “!”.

In mathematics the symbol represents the factorial operation. The expression n! means "the product of the integers from 1 to n". For example, 4! (read four factorial) is 4 × 3 × 2 × 1 = 24. (0! is defined as 1, which is a neutral element in multiplication, not multiplied by anything.)

We want you to help us with this formation: (0! + 1! + 2! + 3! + 4! + ... + n!)%m.

输入

The first line consists of an integer T, indicating the number of test cases.

Each test on a single consists of two integer n and m.

0 < T <= 20
0 <= n < 10
100 (without leading zero)
0 < m < 1000000

输出

Output the answer of (0! + 1! + 2! + 3! + 4! + ... + n!)%m.

示例输入

1 10 861017

示例输出

593846

 

3、超时代码:

#include
#include
int dp[1000005];int jie(int n){ int ans=1; if(dp[n]!=0) return dp[n]; for(int i=n;i>=1;i--) { if(dp[i]!=0) { ans*=dp[i]; break; } else ans*=i; } return ans;}int main(){ int t,n,m; scanf("%d",&t); memset(dp,0,sizeof(dp)); for(int i=0;i
m) n=m-1; for(int j=0;j<=n;j++) { dp[j]=jie(j); sum+=dp[j]%m; } printf("%lld\n",sum%m); } return 0;}

 

转载地址:http://ieddi.baihongyu.com/

你可能感兴趣的文章
JVM最简生存指南
查看>>
漂亮的代码,糟糕的行为——解决Java运行时的内存问题
查看>>
Java的对象驻留
查看>>
logback高级特性使用(二) 自定义Pattern模板
查看>>
JVM并发机制探讨—内存模型、内存可见性和指令重排序
查看>>
可扩展、高可用服务网络设计方案
查看>>
如何构建高扩展性网站
查看>>
微服务架构的设计模式
查看>>
持续可用与CAP理论 – 一个系统开发者的观点
查看>>
nginx+tomcat+memcached (msm)实现 session同步复制
查看>>
c++字符数组和字符指针区别以及str***函数
查看>>
c++类的操作符重载注意事项
查看>>
c++模板与泛型编程
查看>>
STL::deque以及由其实现的queue和stack
查看>>
WAV文件解析
查看>>
DAC输出音乐2-解决pu pu 声
查看>>
WPF中PATH使用AI导出SVG的方法
查看>>
WPF UI&控件免费开源库
查看>>
QT打开项目提示no valid settings file could be found
查看>>
Win10+VS+ESP32环境搭建
查看>>