138 条题解
-
4nzhtl1477 LV 10 @ 2014-11-03 21:53:35
P1200ganggang的烦恼
Accepted记录信息
评测状态 Accepted
题目 P1200 ganggang的烦恼
递交时间 2014-11-03 21:53:04
代码语言 C++
评测机 上海红茶馆
消耗时间 0 ms
消耗内存 540 KiB
评测时间 2014-11-03 21:53:05评测结果
编译成功
测试数据 #0: Accepted, time = 0 ms, mem = 540 KiB, score = 25
测试数据 #1: Accepted, time = 0 ms, mem = 540 KiB, score = 25
测试数据 #2: Accepted, time = 0 ms, mem = 540 KiB, score = 25
测试数据 #3: Accepted, time = 0 ms, mem = 540 KiB, score = 25
Accepted, time = 0 ms, mem = 540 KiB, score = 100
代码
#include <stdio.h>
char ans[1000 + 2][7] = { "1F" , "1F" , "2T" , "6F" , "6F" , "3T" , "9F" , "9F" , "9F" , "27F" , "27F" , "36F" , "27F" , "27F" , "45F" , "45F" , "63F" , "63F" , "54F" , "45F" , "54F" , "63F" , "72F" , "99F" , "81F" , "72F" , "81F" , "108F" , "90F" , "126F" , "117F" , "135F" , "108F" , "144F" , "144F" , "144F" , "171F" , "153F" , "108F" , "189F" , "189F" , "144F" , "189F" , "180F" , "216F" , "207F" , "216F" , "225F" , "234F" , "225F" , "216F" , "198F" , "279F" , "279F" , "261F" , "279F" , "333F" , "270F" , "288F" , "324F" , "288F" , "315F" , "306F" , "333F" , "324F" , "351F" , "351F" , "369F" , "342F" , "351F" , "459F" , "423F" , "432F" , "315F" , "378F" , "432F" , "441F" , "432F" , "423F" , "441F" , "450F" , "486F" , "477F" , "486F" , "477F" , "414F" , "495F" , "495F" , "531F" , "549F" , "585F" , "594F" , "540F" , "513F" , "549F" , "585F" , "648F" , "648F" , "639F" , "648F" , "648F" , "639F" , "630F" , "621F" , "702F" , "648F" , "639F" , "594F" , "666F" , "657F" , "657F" , "693F" , "765F" , "666F" , "648F" , "648F" , "729F" , "738F" , "756F" , "774F" , "783F" , "774F" , "738F" , "765F" , "747F" , "855F" , "801F" , "873F" , "828F" , "819F" , "864F" , "927F" , "873F" , "846F" , "846F" , "819F" , "864F" , "927F" , "954F" , "981F" , "954F" , "963F" , "1026F" , "936F" , "1017F" , "972F" , "1017F" , "954F" , "1008F" , "1107F" , "1053F" , "990F" , "990F" , "999F" , "1062F" , "1053F" , "1098F" , "1125F" , "1134F" , "1089F" , "1107F" , "1134F" , "1125F" , "1134F" , "1098F" , "1116F" , "1188F" , "1089F" , "1188F" , "1188F" , "1179F" , "1242F" , "1215F" , "1206F" , "1215F" , "1233F" , "1215F" , "1278F" , "1368F" , "1260F" , "1305F" , "1323F" , "1287F" , "1314F" , "1323F" , "1260F" , "1296F" , "1377F" , "1422F" , "1386F" , "1350F" , "1422F" , "1404F" , "1458F" , "1395F" , "1413F" , "1422F" , "1512F" , "1395F" , "1413F" , "1404F" , "1350F" , "1404F" , "1476F" , "1494F" , "1530F" , "1584F" , "1647F" , "1602F" , "1530F" , "1548F" , "1512F" , "1593F" , "1530F" , "1674F" , "1674F" , "1575F" , "1638F" , "1665F" , "1575F" , "1701F" , "1692F" , "1665F" , "1701F" , "1773F" , "1728F" , "1728F" , "1656F" , "1638F" , "1701F" , "1746F" , "1665F" , "1809F" , "1728F" , "1872F" , "1746F" , "1755F" , "1890F" , "1818F" , "1818F" , "1926F" , "1890F" , "1971F" , "1980F" , "1863F" , "1944F" , "1827F" , "1872F" , "1935F" , "1881F" , "1953F" , "1926F" , "1917F" , "2025F" , "1926F" , "1899F" , "1989F" , "1953F" , "1863F" , "1971F" , "1962F" , "2079F" , "2088F" , "2061F" , "1953F" , "2106F" , "2124F" , "2043F" , "2133F" , "2106F" , "2151F" , "2169F" , "2133F" , "1980F" , "2088F" , "2187F" , "2043F" , "2313F" , "2367F" , "2223F" , "2241F" , "2367F" , "2340F" , "2349F" , "2241F" , "2304F" , "2313F" , "2385F" , "2322F" , "2385F" , "2313F" , "2331F" , "2412F" , "2385F" , "2358F" , "2511F" , "2484F" , "2394F" , "2376F" , "2448F" , "2466F" , "2376F" , "2511F" , "2493F" , "2394F" , "2529F" , "2457F" , "2466F" , "2430F" , "2412F" , "2646F" , "2556F" , "2565F" , "2502F" , "2601F" , "2556F" , "2637F" , "2574F" , "2655F" , "2583F" , "2700F" , "2628F" , "2808F" , "2637F" , "2610F" , "2700F" , "2727F" , "2682F" , "2718F" , "2754F" , "2655F" , "2772F" , "2853F" , "2862F" , "2835F" , "2790F" , "2907F" , "2817F" , "2925F" , "2817F" , "2754F" , "2961F" , "2835F" , "2844F" , "2844F" , "2916F" , "2808F" , "2844F" , "2970F" , "2934F" , "2952F" , "2862F" , "3123F" , "2844F" , "2925F" , "3069F" , "2952F" , "2979F" , "2979F" , "3087F" , "3024F" , "2997F" , "3060F" , "3060F" , "3087F" , "3114F" , "3024F" , "3033F" , "3132F" , "3204F" , "3186F" , "3213F" , "3195F" , "3258F" , "3186F" , "3159F" , "3249F" , "3186F" , "3132F" , "3312F" , "3240F" , "3195F" , "3204F" , "3357F" , "3339F" , "3375F" , "3366F" , "3204F" , "3348F" , "3366F" , "3321F" , "3384F" , "3474F" , "3312F" , "3348F" , "3312F" , "3582F" , "3429F" , "3528F" , "3627F" , "3402F" , "3339F" , "3366F" , "3483F" , "3474F" , "3600F" , "3528F" , "3609F" , "3465F" , "3483F" , "3447F" , "3573F" , "3672F" , "3600F" , "3654F" , "3708F" , "3618F" , "3726F" , "3708F" , "3564F" , "3672F" , "3807F" , "3690F" , "3627F" , "3636F" , "3780F" , "3618F" , "3753F" , "3636F" , "3762F" , "3807F" , "3798F" , "3897F" , "3771F" , "3834F" , "3879F" , "3780F" , "3780F" , "4059F" , "3807F" , "3726F" , "3852F" , "3861F" , "3753F" , "4041F" , "3969F" , "3825F" , "3978F" , "4023F" , "4185F" , "3825F" , "3888F" , "4059F" , "4203F" , "4140F" , "4059F" , "4176F" , "4176F" , "4149F" , "3969F" , "4077F" , "4131F" , "4158F" , "4221F" , "4041F" , "4194F" , "4275F" , "4140F" , "4257F" , "4140F" , "4275F" , "4338F" , "4284F" , "4266F" , "4419F" , "4428F" , "4383F" , "4194F" , "4356F" , "4365F" , "4356F" , "4059F" , "4320F" , "4266F" , "4302F" , "4383F" , "4329F" , "4536F" , "4509F" , "4419F" , "4284F" , "4410F" , "4608F" , "4302F" , "4455F" , "4464F" , "4374F" , "4644F" , "4527F" , "4608F" , "4599F" , "4446F" , "4518F" , "4536F" , "4671F" , "4644F" , "4527F" , "4581F" , "4671F" , "4707F" , "4644F" , "4554F" , "4635F" , "4761F" , "4563F" , "4716F" , "4698F" , "4779F" , "4860F" , "4752F" , "4761F" , "4680F" , "4698F" , "4842F" , "4815F" , "4860F" , "4761F" , "4968F" , "4986F" , "4941F" , "4977F" , "4950F" , "4923F" , "4896F" , "4932F" , "4851F" , "4977F" , "4797F" , "4986F" , "4869F" , "5202F" , "5067F" , "5085F" , "4941F" , "4968F" , "5076F" , "5112F" , "5274F" , "5121F" , "4923F" , "5139F" , "4860F" , "5337F" , "4950F" , "5067F" , "5193F" , "5409F" , "5166F" , "5247F" , "5346F" , "5139F" , "5274F" , "5202F" , "5373F" , "5265F" , "5391F" , "5301F" , "5337F" , "5472F" , "5319F" , "5265F" , "5427F" , "5400F" , "5427F" , "5364F" , "5346F" , "5337F" , "5454F" , "5265F" , "5400F" , "5373F" , "5499F" , "5562F" , "5382F" , "5427F" , "5292F" , "5706F" , "5562F" , "5499F" , "5526F" , "5562F" , "5652F" , "5562F" , "5679F" , "5328F" , "5616F" , "5724F" , "5787F" , "5697F" , "5634F" , "5715F" , "5634F" , "5760F" , "5787F" , "5589F" , "5742F" , "5661F" , "5499F" , "5823F" , "5931F" , "5823F" , "5877F" , "5823F" , "5787F" , "5832F" , "5841F" , "5850F" , "5886F" , "5778F" , "5841F" , "5922F" , "6039F" , "5859F" , "6003F" , "5931F" , "5958F" , "6120F" , "5895F" , "5904F" , "5904F" , "6057F" , "6012F" , "5931F" , "5967F" , "6147F" , "5859F" , "5859F" , "6237F" , "6210F" , "6336F" , "6057F" , "6291F" , "6021F" , "6291F" , "6021F" , "6219F" , "6156F" , "6282F" , "6012F" , "6372F" , "6300F" , "6399F" , "6372F" , "6282F" , "6246F" , "6291F" , "6318F" , "6219F" , "6453F" , "6192F" , "6516F" , "6408F" , "6444F" , "6147F" , "6417F" , "6381F" , "6327F" , "6498F" , "6462F" , "6453F" , "6363F" , "6489F" , "6417F" , "6480F" , "6615F" , "6453F" , "6561F" , "6831F" , "6444F" , "6444F" , "6444F" , "6417F" , "6534F" , "6687F" , "6786F" , "6651F" , "6687F" , "6615F" , "6777F" , "6795F" , "6876F" , "6966F" , "6957F" , "6669F" , "6822F" , "6831F" , "6696F" , "6741F" , "6957F" , "6885F" , "6723F" , "6777F" , "6741F" , "6849F" , "6840F" , "6678F" , "6849F" , "6831F" , "6957F" , "7065F" , "7056F" , "7092F" , "6966F" , "6876F" , "7083F" , "6912F" , "7191F" , "7101F" , "7020F" , "7191F" , "7164F" , "6957F" , "7110F" , "7047F" , "7092F" , "6957F" , "7083F" , "7182F" , "7407F" , "7065F" , "7254F" , "7137F" , "7254F" , "7155F" , "7155F" , "7128F" , "7515F" , "7317F" , "7029F" , "7461F" , "7263F" , "7218F" , "7425F" , "7317F" , "7326F" , "7362F" , "7641F" , "7452F" , "7263F" , "7380F" , "7416F" , "7263F" , "7398F" , "7524F" , "7533F" , "7308F" , "7524F" , "7452F" , "7488F" , "7434F" , "7461F" , "7488F" , "7353F" , "7731F" , "7470F" , "7641F" , "7461F" , "7272F" , "7542F" , "7569F" , "7713F" , "7704F" , "7767F" , "7551F" , "7776F" , "7596F" , "7722F" , "7875F" , "7659F" , "7686F" , "7659F" , "7677F" , "7776F" , "7686F" , "7983F" , "7857F" , "7938F" , "8001F" , "7839F" , "7965F" , "7929F" , "8109F" , "7812F" , "7938F" , "8001F" , "8001F" , "8091F" , "8100F" , "7884F" , "8001F" , "7929F" , "7965F" , "7947F" , "8127F" , "7947F" , "7965F" , "7812F" , "8028F" , "8217F" , "8208F" , "8181F" , "8280F" , "8028F" , "8037F" , "8298F" , "8172F" , "8424F" , "8127F" , "8235F" , "8001F" , "8163F" , "8307F" , "8496F" , "8181F" , "8172F" , "8415F" , "8343F" , "8424F" , "8217F" , "8361F" , "8397F" , "8433F" , "8307F" , "8649F" , "8352F" , "8370F" , "8514F" , "8514F" , "8082F" , "8568F" , "8316F" , "8370F" , "8478F" , "8649F" , "8658F" , "8541F" , "8550F" , "8388F" , "8622F" , "8586F" , "8586F" , "8595F" , "8649F" , "8550F" , "8694F" , "8685F" , "8694F" , "8676F" , "8685F" , "8793F" , "8667F" , "8802F" , "8757F" , "8901F" , "8937F" , "8694F" , "8946F" , "8820F" , "8829F" , "9000F" , "9009F" , "9009F" , "8955F" , "8811F" , "8883F" , "8928F" , "8928F" , "8982F" , "8757F" , "8901F" , "9090F" , "8973F" , "9117F" , "8946F" , "8838F" , "9099F" , "9189F" , "9099F" , "9072F" , "8811F" , "9054F" , "9054F" , "8865F" , "9063F" , "9126F" , "9189F" , "9135F" , "9045F" , "9216F" , "9090F" , "9324F" , "9162F" , "9324F" , "9081F" , "9045F" , "9414F" , "9153F" , "9369F" , "9333F" , "9486F" , "9126F" , "9081F" , "9477F" , "9198F" , "9468F" , "9504F" , "9603F" , "9360F" , "9396F" , "9477F" , "9423F" , "9522F" , "9450F" , "9702F" , "9432F" , "9594F" , "9558F" , "9630F" , "9549F" , "9477F" , "9675F" , "9549F" , "9702F" , "9540F" , "9738F" , "9666F" , "9729F" , "9801F" , "9657F" , "9810F" , "9729F" , "9513F" , "9612F" , "9774F" , "9684F" , "9702F" , "9675F" , "9504F" , "9792F" , "9684F" , "9639F" , "10035F" , "9855F" , "9774F" , "9783F" , "9990F" , "9999F" , "9954F" , "9945F" , "9981F" , "9954F" , "9999F" , "9900F" , "10071F" , "10125F" , "10080F" , "9828F" , "10116F" , "10143F" , "10089F" , "10134F" , "9711F" , "10053F" , "10314F" , "10035F" , "10278F" , "9990F" , "10053F" , "10179F" , "10413F" , "10134F" , "10341F" , "10458F" , "9990F" , "10296F" , "10053F" , "10296F" , "10206F" , "10287F" , "10332F" , "10467F" , "10287F" , "10296F" , "10251F" , "10584F" , "10395F" , "10233F" , "10368F" , "10287F" , "10539F" , "10539F" };
int n;int main()
{
scanf( "%d" , &n );
printf( "%s\n" , ans[n] );
return 0;
}打表王道!
-
22017-05-08 12:42:19@
/* 水题啊 就是个高精度阶乘Orz 因为n>=3时,n!中必定带有因子3, 所以各位数加起来还是有因子3,一定不是素数,只要特判n=2即可 这个结论很奇妙了 所以我们只要求高精度阶乘 然后累加各位上的数就好咯~ QWQ 表示我太弱了高精度竟然都卡了 */ #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int mod=10000; struct bign { int a[mod],len; bign() { memset(a,0,sizeof(a)); a[1]=1; len=1; } bign operator *(const int &b) { bign c; c.len=999; c.a[1]=0; for(int i=1;i<=len;i++) { c.a[i]+=b*a[i]; if(c.a[i]>=mod) { c.a[i+1]+=(c.a[i]/mod); c.a[i]%=mod; } } while(c.a[c.len]==0) c.len--; return c; } }; bign a; int n; int ans; void out(bign x) { for(int i=1;i<=x.len;i++) { int k=x.a[i]; while(k) { ans+=k%10; k/=10; } } cout<<ans; } int main() { cin>>n; for(int i=2;i<=n;i++) a=a*i; out(a); if(n>2) cout<<'F'; else cout<<'T'; return 0; }
-
12018-06-11 03:48:09@
//**java直接用Biginteger高精度搞定**
import java.math.BigInteger;
import java.util.Scanner;/**
*
* @author zhibinchen
*/
public class Main {public static void main(String[] args) {
Scanner r = new Scanner(System.in);
int n;
BigInteger factorial = new BigInteger("1");
BigInteger ii;
String temp;
char[] separated;
int result = 0;
String prime = "T";n = r.nextInt();
if (n != 0) {
for (int i = 1; i <= n; i++) {
ii = new BigInteger(String.valueOf(i));
factorial = ii.multiply(factorial);
}
} else {
factorial = BigInteger.valueOf(0);
}temp = factorial.toString();
separated = temp.toCharArray();for (int i = 0; i < separated.length; i++) {
result += Integer.valueOf(String.valueOf(separated[i]));
}//judge if it is a prime number
/*
if (result != 1 && result != 0) {
for (int i = 2; i <= Math.sqrt(result); ++i) {
if (result % 2 != 0) {
if (i % 2 == 0) {
++i;
}
}
if (result % i == 0) {
prime = "F";
break;
}
}
} else {
prime = "F";
}*/
if (n!=2){
prime = "F";
}
System.out.println(result + prime);
//System.out.println(factorial);
}}
-
12017-03-12 15:54:03@
//直接暴力枚举即可,数据太水,试了一下数据如果是10000只能卡秒过
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>using namespace std;
const int MAX=25000;
int n,i,j,k,a[MAX],ans,len=0;
bool flag;void gjdcf(int a[],int x)
{
int j,s=0,z=0;
for (j=0;j<len;j++)
{
s=a[j]*x+z;
a[j]=s%10;
z=s/10;
}
while (z>0)
{
a[len++]=z%10;
z/=10;
}
}int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin>>n;
len=1; a[0]=1;
for (i=2;i<=n;i++)
{
gjdcf(a,i);
}
for (i=0;i<len;i++) ans+=a[i];
cout<<ans;
k=int(sqrt(ans*1.0));
for (j=2;j<=k;j++)
if (ans%j==0) {cout<<"F"<<endl;flag=true;break;}
if (!flag) cout<<"T"<<endl;
fclose(stdin); fclose(stdout);
return 0;
} -
02017-11-26 16:33:32@
/*Tokgo*/
/*
计算直接高精度没什么好说的
判断素数有一个有趣的规律
各个数位相加是3的倍数的数是三的倍数
当n>=3时n!是3的倍数
因此一定不是素数
另外n==2的时候再特判一下就行了
/
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n;
vector <int> a;
int js;
void AND(int e){
for(int i=0;i<a.size();++i){
a[i]=e;
}
for(int i=0;i<a.size();++i){
if(a[i]>9){
if(i==a.size()-1)
a.push_back(a[i]/10);
else
a[i+1]+=(a[i]/10);
a[i]%=10;
}
}
}
int main() {
cin>>n;
a.push_back(1);
for(int i=2;i<=n;++i){
AND(i);
}
for(int i=a.size()-1;i>-1;--i){
js+=a[i];
}
cout<<js;
if(n>2) cout<<"F";
else if(n==2){
if(js&1){
cout<<"F";
}
else
cout<<"T";
}
else cout<<"F";
return 0;
} -
02017-02-03 16:51:43@
暴力即可 only 480B
c++
#include<stdio.h>
int n,a[11111],top=1,sum;
int gjc(int x)
{
int i;
for(i=1;i<=top;i++)
a[i]*=x;
for(i=1;i<=top+10;i++)
{
if(a[i]>9)
{
a[i+1]+=a[i]/10;
a[i]%=10;
}
if(a[i]!=0)
top=i;
}
}
int main()
{
int i;
a[1]=1;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
gjc(i);
}
for(i=top;i>=1;i--)
sum+=a[i];
printf("%d",sum);
for(i=2;i<sum;i++)
if(sum%i==0)
{
printf("F\n");
return 0;
}
printf("T\n");
return 0;
}
-
02016-12-23 00:38:36@
一遍水过。。。直接套用模板走一发。。以前不是做过大整数相乘吗?然后搬到这里就好了
```c++
#include <cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int multi(char a, char b)
{
return (a - '0') * (b - '0');
}void strMulti(char *a, char *b, char *c)
{
// 最好对a,b和c的合法性进行判断int lenA = strlen(a);
int lenB = strlen(b);
int maxLen = lenA + lenB;
int *p = new int[maxLen];
memset(p, 0, maxLen * sizeof(int)); // 千万要注意不要写成memset(p, 0, maxLen);int i, j;
for(j = lenB - 1; j >= 0; j--)
{
for(i = lenA - 1; i >= 0; i--)
{
p[j + i + 1] += multi(b[j], a[i]);
}
}// 处理进位操作
for(i = maxLen - 1; i >= 1; i--)
{
p[i - 1] += p[i] / 10;
p[i] = p[i] % 10;
}int *s = p;
// m位正整数和n位正整数相乘,结果的位数必然是(m+n-1)位或者(m+n)位
if(0 == p[0])
{
p++;
}int *pTmp = NULL;
for(pTmp = p; pTmp < s + maxLen; pTmp++)
{
*c++ = *pTmp + '0';
}*c = '\0';
delete s;
}void factorial(int n, char *str)
{
int i;
*str = '1';
*(str + 1) = '\0';
char b[5000];
for(i = 1; i <= n; i++)
{
itoa(i, b, 10);
strMulti(str, b, str);
}
}
int panduan(int x)
{
int m = (int)(sqrt(x) + 0.5);
for(int i=2; i <= m; i++)
{
if(x % i == 0) return 0;
}
return 1;
}
int main()
{
char str[5000];
int n,sum=0;
scanf("%d",&n);
factorial(n, str);
int len = strlen(str);
for(int i=0; i < len; i++)
sum += str[i]-'0';
printf("%d",sum);
if( panduan(sum) == 1) printf("T");
else printf("F");return 0;
} -
02016-12-03 15:18:00@
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define LL long long
void mult(int a[],int x){
int i,k=0,t;
for(i=1;i<=a[0]||k;i++){
t=a[i]*x+k;
k=t/10000;
a[i]=t%10000;
}
a[0]=i-1;
}
bool isprime(LL x){
if(x<=1) return false;
for(int i=2;i<x;i++)
if(x%i==0)return false;
return true;
}
LL getnum(int x){
LL re=0;
do{
re+= x % 10;
x/= 10;
}while(x);
return re;
}
int main(){
int n,i;
LL result=0ULL;
int re[100000]={1,1};//
cin>>n;
for(i=1;i<=n;i++){
mult(re,i);
}
for(i=re[0];i>=1;i--){
result+=getnum(re[i]);
}
cout<<result;
if(isprime(result))cout<<"T";
else
cout<<"F";
return 0;
} -
02016-11-04 12:48:49@
import java.math.BigInteger; import java.util.Scanner; public class Main { public static boolean Judge(int n){ if(n <= 1) return false; if(n == 2) return true; if(n % 2 == 0) return false; for(int i = 3;i * i <= n;i ++){ if(n % i == 0) return false; } return true; } public static void main(String[] args) { Scanner Cin = new Scanner(System.in); int n = Cin.nextInt(); if(n == 0){ System.out.println("0F"); }else{ BigInteger re = BigInteger.ONE; for(int i = 1;i <= n;i ++){ re = re.multiply(BigInteger.valueOf(i)); } String tem = re.toString(); // System.out.println(tem); char[] str = tem.toCharArray(); int ans = 0; for(int i = 0;i < str.length;i ++){ ans += (str[i] - '0'); } System.out.printf("%d",ans); if(Judge(ans)) System.out.println("T"); else System.out.println("F"); } } }
仿佛在逗我,第一次tle,再交一次AC。。。
-
02016-09-07 19:12:57@
#include<stdio.h>
int a[100000];
int y;
int main()
{
int n;
scanf("%d",&n);
if(n==0)
{
printf("1T");
}
a[1]=1;
int len=1;
for(int i=2;i<=n;i++)
{
int x;
int tmp=0;
for(int j=1;j<=len;j++)
{
a[j]=i*a[j]+tmp;
tmp=a[j]/10;
a[j]=a[j]%10;
}
while(tmp>0)
{
a[++len]=tmp%10;
tmp/=10;
}
}
int y=0;
for(int i=1;i<=len;i++)
{
y+=a[i];
}
printf("%d",y);
int tmp_=0;
if(y==1)
{
printf("F");
return 0;
}
if(y==2)
{
printf("T");
return 0;
}
if(y==0)
{
printf("F");
return 0;
}
for(int i=2;i*i<=y;i++)
{
if(y%i==0)
{
printf("F");
tmp_++;
break;
}
}
if(tmp_==0)
printf("T");
return 0;
}
样例过不了,但是测评满分 -
02016-08-23 03:13:14@
#include"stdio.h"
#include"iostream"
#include"cstring"
using namespace std;
typedef long long ll;
ll len;
bool is_prime(ll x)
{
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
ll f(ll a[],ll x)
{
for(int i=0;i<len;i++)
a[i]*=x;
for(int i=0;i<len;i++)
if(a[i]>=10)
{
a[i+1]+=a[i]/10;
a[i]%=10;
}
if(a[len]) len++;
while(a[len-1]>=10)
{
a[len]+=a[len-1]/10;
a[len-1]%=10;
len++;
}
}
ll fuck(ll x)
{
int ans=0;
while(x)
{
ans+=x%10;
x/=10;
}
return ans;
}
int main()
{
int n;
cin>>n;
if(n==0) cout<<0<<"F"<<endl;
else
{
ll a[100000];
memset(a,0,sizeof(a));
int i;
a[0]=1;len=1;
for(i=1;i<=n;i++)
f(a,i);
ll ans=0;
for(i=len-1;i>=0;i--)
if(a[i]>=10)ans+=fuck(a[i]);
else ans+=a[i];
cout<<ans;
if(ans%3!=0) cout<<"T"<<endl;
else cout<<"F"<<endl;
/*
double fuck=1;
for(i=1;i<=n;i++)
fuck*=i;
cout<<fuck<<endl;for(i=len-1;i>=0;i--)
cout<<a[i];
cout<<endl;
*/
}
return 0;
} -
02016-07-21 21:19:18@
首先,你需要高精度 //或是自带高精度的Python、Java
另外,因为n>=3时,n!中必定带有因子3,所以各位数加起来还是有因子3,一定不是素数,只要特判n=2即可
```python
from functools import *
from math import *
from string import *n=int(input())
mul=1
i=1
while i<=n:
mul=mul*i
i=i+1s=str(mul)
sum = 0
for c in s:
sum = sum + int(c)if n == 2:
print (str(sum)+'T')
else:
print (str(sum)+'F') -
02016-07-16 19:51:01@
#include<iostream>
#include<cstdio>
#include<cstring>using namespace std;
#define LL long longvoid mult(int a[],int x){//高精度乘法
int i,k=0,t;for(i=1;i<=a[0]||k;i++){
t=a[i]*x+k;
k=t/10000;//万进制 压缩
a[i]=t%10000;
}
a[0]=i-1;
}bool isprime(LL x){
if(x<=1) return false;for(int i=2;i<x;i++)
if(x%i==0)return false;
return true;//判断是否是素数
}LL getnum(int x){
LL re=0;do{
re+= x % 10;//各个位数相加
x/= 10;
}while(x);
return re;
}
int main(){
int n,i;
LL result=0ULL;
int re[100000]={1,1};cin>>n;
for(i=1;i<=n;i++){
mult(re,i);
}
for(i=re[0];i>=1;i--){
result+=getnum(re[i]);
}
cout<<result;
if(isprime(result))cout<<"T";
else
cout<<"F";
return 0;
} -
02016-04-02 09:33:39@
#include<cstdio>
#include<cstring>
using namespace std;
int num[100005];
bool judge(int x)
{
if(n<=1)
return false;
for(int i=2;i*i<=x;i++)
{
if(x%i==0)
return false;
}
return true;
}
int main()
{
int n;
scanf("%d",&n);
num[0]=1;
int len=1;
for(int e=2;e<=n;e++)
{
int x;
int jin=0;
for(int i=0;i<len;i++)
{
x=(e*num[i]+jin);
jin=x/10;
num[i]=x%10;
}while(jin!=0)
{
num[len++]=jin%10;
jin/=10;
}}
int sum=0;
for(int i=0;i<len;i++)
{
sum+=num[i];
}
printf("%d%c\n",sum,judge(sum)?'T':'F');return 0;
} -
02016-03-22 07:30:33@
编译成功
测试数据 #0: Accepted, time = 0 ms, mem = 948 KiB, score = 25
测试数据 #1: Accepted, time = 0 ms, mem = 948 KiB, score = 25
测试数据 #2: Accepted, time = 0 ms, mem = 948 KiB, score = 25
测试数据 #3: Accepted, time = 0 ms, mem = 952 KiB, score = 25
Accepted, time = 0 ms, mem = 952 KiB, score = 100
-
02015-11-03 10:09:12@
Program P1200;
type wbd=array[1..50000]of longint;
var k,n,y:longint;a:wbd;bo:boolean;
procedure fuck(n:longint);
var x,i:longint;
begin
x:=0;
for i:=1 to k do begin
a[i]:=a[i]*n+x;
x:=a[i] div 10;
a[i]:=a[i] mod 10;
end;
while x>0 do begin
inc(k);
a[k]:=x mod 10;
x:=x div 10;
end;
end;Procedure wq;
var i:longint;
begin
k:=1;a[1]:=1;
for i:=1 to n do fuck(i);
y:=0;
for i:=1 to k do inc(y,a[i]);
end;function check(t:longint):boolean;
var i:longint;
begin
if (t=2) or (t=3) then exit(true);
for i:=2 to trunc(sqrt(t)) do
if t mod i=0 then exit(false);
exit(true);
end;begin
readln(n);
if (n=0) or (n=1) then begin
writeln(n,'F'); halt; end;
wq;
write(y);
bo:=check(y);
if bo then writeln('T')
else writeln('F');
end. -
02015-07-31 15:19:12@
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;int num[1000];
int len(){
for(int i=999; i>=1; i--)
if(num[i] != 0)
return i;
}int main()
{
memset(num, 0, sizeof(num));
int n;
cin>>n;
num[1] = 1;
for(int i=2; i<=n; i++){
int k=len();
for(int j=1; j<=k; j++){
num[j] *= i;
for(int i=1; i<=len(); i++){
num[i+1] += num[i]/10;
num[i] %= 10;
}
}
int ans=0;
for(int i=1; i<=len(); i++)
ans += num[i];
cout<<ans;
for(int i=2; i<=sqrt(ans); i++)
if(num[i] % i ==0){
cout<<"F";
system("pause");
return 0;
}
cout<<"T";
system("pause");
return 0;
}
高精度 -
02015-07-14 10:37:38@
一遍水过
#include <iostream>
#include <math.h>
using namespace std;
int n,jie[100001],l,s;
int main()
{
cin >> n;
jie[1]=1;
l=1;
for (int i=2;i<=n;i++)
{
for (int j=1;j<=l;j++)
jie[j]*=i;
for (int j=1;j<=l;j++)
if(jie[j]>9)
{
jie[j+1]+=jie[j]/10;
jie[j]%=10;
if(j==l) l++;
}
}
for (int i=l;i>=1;i--)
s+=jie[i];
cout << s;
bool f=true;
for (int i=2;i<=sqrt(s);i++)
if(s%i==0)
{
f=false;
break;
}
if(f) cout << 'T' << endl;
else cout << 'F' << endl;
return 0;
} -
02015-03-07 21:26:35@
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<time.h>
int p[1001];
int r[5001];
void mul(int *r,int m)
{
int i,jw=0;
for(i=0;i<5000;i++)
{
r[i]=r[i]*m;
r[i]=r[i]+jw;
jw=r[i]/10;
r[i]=r[i]%10;
}
}
int is(int pr)
{
if(pr==1)
{
return 0;
}
else
{
if(pr==2)return 1;
int i;
for(i=2;i<=sqrt(pr);i++)
{
if(pr%i==0)
{
return 0;
break;
}
}
return 1;
}
}
int sum(int *a)
{
int i,ans=0;
for(i=4999;i>=0;i--)
{
if(a[i]!=0)break;
}
if(i==-1)ans=0;
else
{
for(;i>=0;i--)
{
ans+=a[i];
// printf("%d",a[i]);
}
//printf("\n");
}
return ans;
}int main()
{
int j,n,i,k=0,jw,pr;
char c;
scanf("%d",&n);
for(i=0;i<n;i++)
{
p[i]=i+1;
}
r[0]=1;
for(i=0;i<n;i++)
{
mul(r,p[i]);
}
pr=sum(r);
if(is(pr)==1)
{
c='T';
}
else
{
c='F';
}
//print(r);
printf("%d%c\n",pr,c);
//system("pause");
return 0;
}
AC 112 纪念 -
02014-12-29 18:01:24@
type lll=longint;
arr=array[0..1000] of lll; var i,j,k,Base,n:lll;
st:string;
res,a,x:arr;
function F(a,b,n:longint):longint;
var s:longint;
begin
s:=1;
while b>0 do
begin
if odd(b) then
s:=(s*a) mod n;
b:=b shr 1;
a:=(a*a) mod n;
end;
exit(s);
end;
function P(n,s:longint):boolean;
var a,i:longint;
begin
if n<=1 then exit(false);
randomize;
p:=true;
for i:=1 to s do
begin
a:=random(n-1)+1;
if F(a,n-1,n)<>1 then exit(false);
end;
end;
procedure C(v:longint);
var rem,o:lll;
begin
fillchar(x,sizeof(x),0);
rem:=0;
o:=1;
while (o<=res[0])or(rem>0) do
begin
if o<=res[0] then inc(rem,res[o]*v);
x[o]:=rem mod 10;
rem:=rem div 10;
inc(o);
end;
x[0]:=o-1;
while (x[0]>0)and(x[x[0]]=0) do dec(x[0]);
res:=x;
end;
Begin
readln(st);
res[0]:=1;
res[1]:=1;
val(st,k);
for i:=2 to k do
C(i);
n:=0;
for i:=1 to res[0] do inc(n,res[i]);
write(n);
if P(n,2) then write('T')
else
write('F');
end.