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. Sqli-labs less 40

    Less-40 本关的sql语句为SELECT * FROM users WHERE id=('$id') LIMIT 0,1 我们根据sql语句构造以下的payload: http://127.0. ...

  2. swappiness

    在ubuntu 里面,swappiness的值的大小对如何使用swap分区是有着很大的联系的.swappiness=0的时候表示最大限度使用物理内存,然后才是 swap空间,swappiness=10 ...

  3. 由浅入深了解Thrift之微服务化应用架构

    为什么选择微服务 一般情况下,业务应用我们都会采用模块化的分层式架构,所有的业务逻辑代码最终会在一个代码库中并统一部署,我们称这种应用架构为单体应用. 单体应用的问题是,全部开发人员会共享一个代码库, ...

  4. hdu 4850 Wow! Such String!(字符串处理,yy)

    题目 参考了博客http://blog.csdn.net/u013368721/article/details/37575165 //用visit[26][26][26][26]来判断新家新区的子母河 ...

  5. iOS网络检测

    使用之前请从Apple网站下载示例:点此下载 Reachability 中定义了3种网络状态: typedef enum : NSInteger { NotReachable = ,//无网络 Rea ...

  6. POJ 1469

    #include<iostream> #include<stdio.h> #include <string.h> #include <vector> # ...

  7. POJ 1631

    #include <iostream> #define MAXN 500005 using namespace std; int T[MAXN]; int binary_search(in ...

  8. POJ 1504

    #include<iostream> using namespace std; int main() { int num; cin>>num; while(num--){ in ...

  9. Android 4.4KitKat AudioRecord 流程分析

    Android是架构分为三层: 底层      Linux Kernel 中间层  主要由C++实现 (Android 60%源码都是C++实现) 应用层  主要由JAVA开发的应用程序 应用程序执行 ...

  10. CF 50E. Square Equation Roots

    思路:这题的关键就是重复根只可能是整数. 这样先求出所有的根的数目,在减去重复的根. 代码如下: #include <iostream> #include <cstring> ...