1343

想了好一会 以为会有什么定理呢 没想到 就试着搜了 看来素数还是很多的 跑的飞快

注意会有前导0的情况 还有0,1不是素数。。。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define LL long long
int flag;
char a[];
LL p[];
int judge(LL x)
{
if(x<)return ;
int i,o = sqrt(x*1.0);
for(i = ; i <= o+ ; i++)
if(x%i==)
return ;
return ;
}
void dfs(int x,LL s,int pa[])
{
if(flag) return ;
int i;
if(x>)
{
if(judge(s))
{
for(i = ; i <= ; i++)
cout<<pa[i];
puts("");
flag = ;
}
return ;
}
for(i = ; i <= ; i++)
{
s+=p[-x]*i;
pa[x] = i;
dfs(x+,s,pa);
s-=p[-x]*i;
}
}
int main()
{
int i,n;
int pa[];
LL s=;
cin>>n;
p[] = ;
for(i = ; i <= ; i++)
p[i] = p[i-]*;
for(i = ; i <= n ; i++)
{
cin>>a[i];
pa[i] = a[i]-'';
s+=(a[i]-'')*p[-i];
}
if(n==)
{
printf("%lld\n",s);
return ;
}
dfs(n+,s,pa);
return ;
}

1343. Fairy Tale的更多相关文章

  1. ural 1343. Fairy Tale

    1343. Fairy Tale Time limit: 1.0 secondMemory limit: 64 MB 12 months to sing and dance in a ring the ...

  2. Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale 二分

    C. Anton and Fairy Tale 题目连接: http://codeforces.com/contest/785/problem/C Description Anton likes to ...

  3. NSOJ A fairy tale of the two(最小费用最大流、SPFA版本、ZKW版本)

    n,m<=20,给两个n×m布尔矩阵,每次操作可将第一个矩阵的2个相邻元素互换.输出最少操作次数使得两个矩阵完全一样. 比赛的时候想过按照二分图完美匹配的类似做法构图,不过想到边太多以及卡各种题 ...

  4. C. Anton and Fairy Tale

    链接 [https://codeforces.com/contest/785/problem/C] 题意 初始时有n,第1天先加m开始吃1,但总的不能超过n,第i天先加m开始吃i(如果不够或刚好就吃完 ...

  5. CodeForces 785C Anton and Fairy Tale

    二分. 如果$n≤m$,显然只能$n$天. 如果$n>m$,至少可以$m$天,剩余还可以支撑多少天,可以二分计算得到,也可以推公式.二分计算的话可能爆$long$ $long$,上了个$Java ...

  6. 【二分】Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale

    当m>=n时,显然答案是n: 若m<n,在第m天之后,每天粮仓减少的量会形成等差数列,只需要二分到底在第几天,粮仓第一次下降到0即可. 若直接解不等式,可能会有误差,需要在答案旁边扫一下. ...

  7. CodeForces 785C Anton and Fairy Tale 二分

    题意: 有一个谷仓容量为\(n\),谷仓第一天是满的,然后每天都发生这两件事: 往谷仓中放\(m\)个谷子,多出来的忽略掉 第\(i\)天来\(i\)只麻雀,吃掉\(i\)个谷子 求多少天后谷仓会空 ...

  8. 【codeforces 785C】Anton and Fairy Tale

    [题目链接]:http://codeforces.com/contest/785/problem/C [题意] 容量为n的谷仓,每一天都会有m个谷子入仓(满了就视为m);第i天 会有i只鸟叼走i个谷子 ...

  9. C. Anton and Fairy Tale(数学推式子)

    \(数学题,式子并不难推,但边界是真的烦\) \(\color{Red}{Ⅰ.其实可以发现,当m>=n时,每次都可以粮食补到n,所以一定是在第n天消耗完毕}\) \(\color{Purple} ...

随机推荐

  1. .Net 命名(委托,事件==)

    委托及参数命名: public delegate void ClickedEventHandler(object sender, ClickedEventArgs e); ClickedEventHa ...

  2. google大赛 入围赛250分真题

    Problem StatementYou have a collection of music files with names formatted as "genre-artist-alb ...

  3. 1303: [CQOI2009]中位数图

    早起一AC,整天萌萌哒. Problem: 1303 User: forgot93 Language: C++ Result: Accepted Time:56 ms Memory:2108 kb * ...

  4. Working with LOBs in Oracle and PHP

    原文链接:http://www.oracle.com/technetwork/articles/fuecks-lobs-095315.html Working with LOBs in Oracle ...

  5. unity android 集成指南

    原地址:http://blog.csdn.net/alking_sun/article/details/36175187 1.安卓层开发并暴露接口.   launcher activity(以下称为U ...

  6. Unity使用外部版本控制SVN

    原地址:http://www.cnblogs.com/realtimepixels/p/3652146.html Using External Version Control Systems with ...

  7. netaddr 0.7.12

    Pythonic manipulation of IPv4, IPv6, CIDR, EUI and MAC network addresses https://pypi.python.org/pyp ...

  8. Flex +WebService

    <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="h ...

  9. sql 语句的各种连接

    数据表: 1.两种连接表现方式一样 其中 where 条件语句可以省略,当时join 的on 语句不可省略 2.左连接,右连接 左连接:返回左表的所有数据,并根据条件返回左右表的连接结果,如果未匹配到 ...

  10. hdu 4759 Poker Shuffle 二进制

    思路:主要是二进制的运用. 为了方便从0开始,首先看下右移一下,高位异或1的规律:(可以从右往左一列一列看) 000(0) -> 100(4) -> 110(6) -> 111(7) ...