1343. Fairy Tale
想了好一会 以为会有什么定理呢 没想到 就试着搜了 看来素数还是很多的 跑的飞快
注意会有前导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的更多相关文章
- 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 ...
- 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 ...
- NSOJ A fairy tale of the two(最小费用最大流、SPFA版本、ZKW版本)
n,m<=20,给两个n×m布尔矩阵,每次操作可将第一个矩阵的2个相邻元素互换.输出最少操作次数使得两个矩阵完全一样. 比赛的时候想过按照二分图完美匹配的类似做法构图,不过想到边太多以及卡各种题 ...
- C. Anton and Fairy Tale
链接 [https://codeforces.com/contest/785/problem/C] 题意 初始时有n,第1天先加m开始吃1,但总的不能超过n,第i天先加m开始吃i(如果不够或刚好就吃完 ...
- CodeForces 785C Anton and Fairy Tale
二分. 如果$n≤m$,显然只能$n$天. 如果$n>m$,至少可以$m$天,剩余还可以支撑多少天,可以二分计算得到,也可以推公式.二分计算的话可能爆$long$ $long$,上了个$Java ...
- 【二分】Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale
当m>=n时,显然答案是n: 若m<n,在第m天之后,每天粮仓减少的量会形成等差数列,只需要二分到底在第几天,粮仓第一次下降到0即可. 若直接解不等式,可能会有误差,需要在答案旁边扫一下. ...
- CodeForces 785C Anton and Fairy Tale 二分
题意: 有一个谷仓容量为\(n\),谷仓第一天是满的,然后每天都发生这两件事: 往谷仓中放\(m\)个谷子,多出来的忽略掉 第\(i\)天来\(i\)只麻雀,吃掉\(i\)个谷子 求多少天后谷仓会空 ...
- 【codeforces 785C】Anton and Fairy Tale
[题目链接]:http://codeforces.com/contest/785/problem/C [题意] 容量为n的谷仓,每一天都会有m个谷子入仓(满了就视为m);第i天 会有i只鸟叼走i个谷子 ...
- C. Anton and Fairy Tale(数学推式子)
\(数学题,式子并不难推,但边界是真的烦\) \(\color{Red}{Ⅰ.其实可以发现,当m>=n时,每次都可以粮食补到n,所以一定是在第n天消耗完毕}\) \(\color{Purple} ...
随机推荐
- SSH无密码验证
一.安装和启动SSH协议 sudo yum install ssh sudo yum install rsync service sshd restart 启动服务 (rsync是一个远程数据同步工具 ...
- Mac下使用Apache TCPMon
Mac下使用Apache TCPMon 参考链接: TCPMon Tutorial Anyone know how to get TCPMON working on a mac? Apache TCP ...
- Unity3D开发Windows Store应用程序 注意事项
原地址:http://blog.csdn.net/jbjwpzyl3611421/article/details/12704491 针对最近在移植window store项目中遇到的问题,我整理了官方 ...
- 2016年度 JavaScript 展望(上)
[编者按]本文作者为资深 Web 开发者 TJ VanToll, TJ 专注于移动端 Web 应用及其性能,是<jQuery UI 实践> 一书的作者. 本文系 OneAPM 工程师编译呈 ...
- Ruby Profiler 详解之 ruby-prof(I)
项目地址: ruby-prof 在上一篇 Ruby 中的 Profiling 工具中,我们列举了几种最常用的 Profiler,不过只是简单介绍,这一次详细介绍一下 ruby-prof 的使用方法. ...
- (转)Fibonacci Tilings
Fibonacci numbers {Fn, n ≥ 0} satisfy the recurrence relation (1) Fn+2 = Fn+1 + Fn, along with the i ...
- sparksql链接mysql
1.在IDEA上建立一个sparksql_mysql的scala对象. 2.连接mysql的代码如下 import java.sql.{DriverManager, PreparedStatement ...
- App接口设计1
http://blog.csdn.net/newjueqi/article/details/44062849 http://www.tuicool.com/articles/YNZBna http:/ ...
- PHP函数中默认参数的的写法
函数可以定义 C++ 风格的标量参数默认值,如下所示: Example #3 在函数中使用默认参数 <?php function makecoffee($type = "cappucc ...
- C# 调用Windows API实现两个进程间的通信
使用Windows API实现两个进程间(含窗体)的通信http://blog.csdn.net/huangxinfeng/article/details/5513608 从C#下使用WM_COPYD ...