23 条题解
-
14
zone LV 10 @ 8 年前
n>m时
n!=1*2*.......*m*...*n;
n! % m =0
所以if(n>=m)n=m;
-
58 年前@
-
06 年前@
p党来了
var
a,b,s,j:int64;
i:longint;
begin
read(a,b);
if a>b then a:=b-1;
s:=1;
for i:=1 to a do
begin
s:=s*i;
s:=s mod b;
j:=j+s;
end;
write(j mod b);
end. -
06 年前@
-
08 年前@
数据有毒
编译成功测试数据 #0: WrongAnswer, time = 0 ms, mem = 560 KiB, score = 0
测试数据 #1: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 556 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 552 KiB, score = 10
测试数据 #5: Accepted, time = 15 ms, mem = 556 KiB, score = 10
测试数据 #6: Accepted, time = 15 ms, mem = 556 KiB, score = 10
测试数据 #7: Accepted, time = 15 ms, mem = 556 KiB, score = 10
测试数据 #8: Accepted, time = 15 ms, mem = 556 KiB, score = 10
测试数据 #9: Accepted, time = 15 ms, mem = 556 KiB, score = 10
WrongAnswer, time = 90 ms, mem = 560 KiB, score = 90九次WA了。。。
-
09 年前@
###pascal code
program P1964;
var ans,i:longint;
sum,n,m:int64;
begin
read(n,m); sum:=1; if n>1000000 then n:=m;
for i:=1 to n do
begin
sum:=sum*i mod m; ans:=(ans+sum) mod m;
end;
write(ans);
end. -
09 年前@
终于ac。。。
-
09 年前@
测试数据 #8?
-
09 年前@
Block code
#include<cstdio>
int main()
{
long long n,m,t=1,ans=0;
scanf("%lld%lld",&n,&m);
if(n>=m) n=m-1;
for(int i=1;i<=n;i++)
{
t=(t*i)%m;
ans+=t;}
ans%=m;
printf("%lld",ans);
return 0;}
用一个变量累成×,再一个变量累加就好了,累×变量实时取模,累加变量用long long,最后一次取模节省时间
当n>=m时,n! % m==0,所以后面的全部忽略掉,累加到(m-1)!过 -
09 年前@
#include <cstdio>
int main()
{
long long n;
int m;
scanf("%I64d %d", &n, &m);
if (n > m)
n = m;
int ans = 0;
int temp = 1;
for (int i = 1; i <= n; i++)
{
temp = temp * i % m;
ans = (ans + temp) % m;
}
printf("%d\n", ans);
return 0;
}为什么
测试数据 #0: Accepted, time = 0 ms, mem = 444 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 448 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 444 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 440 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 448 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 448 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 440 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 440 KiB, score = 10
测试数据 #8: WrongAnswer, time = 15 ms, mem = 440 KiB, score = 0
测试数据 #9: Accepted, time = 15 ms, mem = 448 KiB, score = 10
WrongAnswer, time = 45 ms, mem = 448 KiB, score = 90 -
09 年前@
program alisky;
var n,m,sum,tot,past,past1:qword;
i:longint;
begin
readln(n,m);
sum:=1;tot:=1;
for i:=2 to n do
begin
if (i>=m) then break;
tot:=tot*i mod m;
sum:=(sum+tot) mod m;
end;
writeln(sum);
end.
@少女夜夜
为什么这个第六组过不了 -
09 年前@
大神看看哪错了?爆了第九个点
#include<stdio.h>
#include<iostream>
using namespace std;
int x[1010000];
int main(){
int m;
long long n;
scanf("%lld%d",&n,&m);
if (n>m) n=m;
x[0]=1;
int sum=0;
for (int i=1;i<=n;i++)
{
x[i]=(x[i-1]*i)%m;
sum=(sum +x[i]) %m;
}
printf("%d\n",sum);
} -
-18 年前@
-
-18 年前@
{
N<=1000000000000000000,M<=1000000比M大的直接忽略。 (因为 mod M)
}
```PASCAL
var
i:longint;
N,M,tmp,ans:int64;begin
readln(N,M);
if N>M then N:=M-1;
tmp:=1;
for i:=1 to N do
begin
tmp:=(tmp*i)mod M;
if tmp=0 then break;
ans:=(ans+tmp) mod M;
end;
writeln(ans);
end.``` -
-18 年前@
一组大数据WA掉了,求大神帮忙看看!!!
#include<iostream>
using namespace std;
long long m,n;
int main ()
{
cin>>n>>m;
int ans=0,sum=1;
for (int i=1;i<=min(n,m);i++)
{
sum=(i*sum)%m;
ans=(ans+sum)%m;
}
cout<<ans;
return 0;
} -
-18 年前@
求指教,后面四组大数据过不了,怎么解决?
#include <iostream>
using namespace std;
int m,n;int main ()
{
cin>>n>>m;
int ans=0,sum=1;
for (int i=1;i<=n;i++)
{
sum=(i*sum)%m;
ans=(ans+sum)%m;
}
cout<<ans;
return 0;
} -
-19 年前@
希望大家帮忙解答一下,这段代码后四个全都WA
import java.util.Scanner;
java
class Main
{
public static void main(String[] args)
{
Scanner in= new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
long difficulty = 1;
long total=0;
int i = 0;
while (i!=n)
{
i++;
difficulty = difficulty*i%m;
total =(total+ difficulty)%m;
}
System.out.println(total);
}
}
-
-19 年前@
根据mod的性质,只要在阶乘和中找到一个和 mod m=0,那么之后的数据都可以舍去,因为 m! mod m=0 所以最大就找到m。
#include <iostream>
using namespace std;
long long int n,m,s=0,t=1;
int main()
{
cin>>n>>m;
if(n>=m)n=m;
for(long long int i=1;i<=n;i++)
{
t=(t*i)%m;
s=(s+t)%m;
}
cout<<s%m;
return 0;
} -
-19 年前@
/*
Author : Slience_K
Belong : C++
Pro : Vijos P 1964*/
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
LL n , m , ans , sum;
int main(){
freopen( "P1964.in" , "r" , stdin );
scanf( "%I64d%I64d" , &n , &m );
n = min( n , m - 1 );
sum = 1;
ans = 0;
for( int i = 1 ; i <= n ; i++ ){
sum *= i;
sum %= m;
ans = ( ans + sum ) % m;
}
printf( "%I64d" , ans );
return 0;
} -
-19 年前@
#include<iostream>
int main()
{
unsigned long long n;
long m;
std::cin>>n>>m;
long long ans(1);
long long cnt(1);
for(long i=2;cnt!=0&&i<=n;i++)
{
cnt=(cnt*i)%m;
ans=(ans+cnt)%m;
}
std::cout<<ans;
return 0;
}