ural 1343. Fairy Tale
1343. Fairy Tale
Memory limit: 64 MB
Input
Output
Sample
input | output |
---|---|
5 |
646310554187 |
Problem Source: USU Championship 2004
/**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name)
{
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = ;
int Prime[N], Tot;
bool Visit[N];
int m;
LL n, Fact[]; inline void getPrime()
{
For(i, , N - )
{
if(!Visit[i]) Prime[++Tot] = i;
For(j, , Tot)
{
if(i * Prime[j] >= N) break;
Visit[i * Prime[j]] = ;
if(i % Prime[j] == ) break;
}
}
} inline void Input()
{
getPrime();
scanf("%d", &m);
if(m) cin >> n;
} inline bool isPrime(LL x)
{
if(x <= ) return ;
For(i, , Tot)
{
if(x <= Prime[i]) break;
if(x % Prime[i] == ) return ;
}
return ;
} inline void Solve()
{
srand(time());
Fact[] = ;
For(i, , ) Fact[i] = Fact[i - ] * 10LL; LL Tmp = n * Fact[ - m];
//isPrime(277717333835LL);
while(!isPrime(Tmp))
{
Tmp = n * Fact[ - m];
For(i, m + , )
Tmp += (rand() % ) * Fact[ - i];
} printf("%012I64d\n", Tmp);
} int main()
{
#ifndef ONLINE_JUDGE
SetIO("F");
#endif
Input();
Solve();
return ;
}
ural 1343. Fairy Tale的更多相关文章
- 1343. Fairy Tale
1343 想了好一会 以为会有什么定理呢 没想到 就试着搜了 看来素数还是很多的 跑的飞快 注意会有前导0的情况 还有0,1不是素数... #include <iostream> #inc ...
- 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 ...
- URAL 1513 Lemon Tale
URAL 1513 思路: dp+高精度 状态:dp[i][j]表示长度为i末尾连续j个L的方案数 初始状态:dp[0][0]=1 状态转移:dp[i][j]=dp[i-1][j-1](0<=j ...
- URAL 1513. Lemon Tale(简单的递推)
写几组数据就会发现规律了啊. .但是我是竖着看的.. .还找了半天啊... 只是要用高精度来写,水题啊.就当熟悉一下java了啊. num[i] = 2*num[i-1]-num[i-2-k]. 15 ...
- 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\)个谷子 求多少天后谷仓会空 ...
随机推荐
- Swift - 文本输入框(UITextField)
1,文本框的创建,有如下几个样式: UITextBorderStyle.none:无边框 UITextBorderStyle.line:直线边框 UITextBorderStyle.roundedRe ...
- IT人学习方法论(一):学习方向
07年的时候曾经讲过一节Webcast,名叫<使您成为Windows专家的一些学习习惯 >.直到最近,还经常收到听众关于这一节课反馈和心得的电子邮件,可见学习方法论是大家非常关心的问题.因 ...
- 按键的使用(一)------verilog
按键在项目中应用还是很频繁的,这里主要介绍按键的几种用法. 1.按下一次有效:按下一次计数器增加一下. 2.按下连续有效:按下不松,计数器就一直增加. 3.按下无效,松开有效:按下时计数器值不变,按键 ...
- 《CLR via C#》读书笔记(1)CLR执行模型
1.1 释义 CLR 公共语音运行时 Common Language Runtime CTS 通用类型系统 Common Type System CTS.CLS是CLR的核心 CLS 通用语言规范 C ...
- JAVA基础学习之IP简述使用、反射、正则表达式操作、网络爬虫、可变参数、了解和入门注解的应用、使用Eclipse的Debug功能(7)
1.IP简述使用//获取本地主机ip地址对象.InetAddress ip = InetAddress.getLocalHost();//获取其他主机的ip地址对象.ip = InetAddress. ...
- 【Java EE 学习 21 上】【其它类型的监听器】【使用HttpSessionActivationListener监听session的活化和钝化】
一.ServletContextListener Method Summary void contextDestroyed(ServletContextEvent sce) R ...
- OCJP(1Z0-851) 模拟题分析(二)over
Exam : 1Z0-851 Java Standard Edition 6 Programmer Certified Professional Exam 以下分析全都是我自己分析或者参考网上的,定有 ...
- centos(x86 64位系统)使用boost
1. 安装gcc,g++,make等开发环境 yum groupinstall "Development Tools" 2. 安装boost yum install boost b ...
- Win10 for Phone 裁剪控件
<Page.BottomAppBar> <CommandBar x:Name="appBar"> <AppBarButton Label=" ...
- 使用PHP获取时间今天 明天 昨天 时间戳的详解
使用php获取时间今天明天昨天时间戳 2013-06-20 11:12 <?php echo "今天:".date("Y-m-d")."< ...