Codeforces Round #279 (Div. 2) C. Hacking Cypher 前缀+后缀
1 second
256 megabytes
standard input
standard output
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
The first line of the input contains the public key of the messenger — an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 ≤ a, b ≤ 108).
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines — the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
116401024
97 1024
YES
11640
1024
284254589153928171911281811000
1009 1000
YES
2842545891539
28171911281811000
120
12 1
NO
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e6+,M=4e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+,MOD=1e9+;
char a[N];
int prex[N];
int prey[N];
int quick(ll x,int y,int mod)
{
ll ans=;
while(y)
{
if(y&)ans*=x,ans%=mod;
x*=x;
y>>=;
x%=mod;
}
return ans;
}
int main()
{
int x,y;
scanf("%s",a+);
int len=strlen(a+);
scanf("%d%d",&x,&y);
for(int i=;i<=len;i++)
prex[i]=(prex[i-]*+(a[i]-''))%x;
for(int i=len,j=;i>=;i--,j++)
prey[i]=(prey[i+]+(a[i]-'')*quick(,j,y))%y;
for(int i=;i<len;i++)
{
if(prex[i]==&&prey[i+]==&&a[i+]!='')
{
printf("YES\n");
for(int j=;j<=i;j++)
printf("%c",a[j]);
printf("\n");
for(int j=i+;j<=len;j++)
printf("%c",a[j]);
printf("\n");
return ;
}
}
printf("NO\n");
return ;
}
Codeforces Round #279 (Div. 2) C. Hacking Cypher 前缀+后缀的更多相关文章
- Codeforces Round #279 (Div. 2) C. Hacking Cypher (大数取余)
题目链接 C. Hacking Cyphertime limit per test1 secondmemory limit per test256 megabytesinputstandard inp ...
- Codeforces Round #279 (Div. 2) C. Hacking Cypher 机智的前缀和处理
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #incl ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #279 (Div. 2) 题解集合
终于有场正常时间的比赛了...毛子换冬令时还正是好啊233 做了ABCD,E WA了3次最后没搞定,F不会= = 那就来说说做的题目吧= = A. Team Olympiad 水题嘛= = 就是个贪心 ...
- Codeforces Round #279 (Div. 2) vector
A. Team Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #279 (Div. 2) E. Restoring Increasing Sequence 二分
E. Restoring Increasing Sequence time limit per test 1 second memory limit per test 256 megabytes in ...
- CodeForces Round #279 (Div.2)
A: 题意: 有三个项目和n个学生,每个学生都擅长其中一个项目,现在要组成三个人的队伍,其中每个人恰好擅长其中一门,问能组成多少支队伍. 分析: 最多能组成的队伍的个数就是擅长项目里的最少学生. #i ...
- 【Codeforces Round#279 Div.2】B. Queue
这题看别人的.就是那么诚实.http://www.cnblogs.com/zhyfzy/p/4117481.html B. Queue During the lunch break all n Ber ...
- Codeforces Round #279 (Div. 2)f
树形最大上升子序列 这里面的上生子序列logn的地方能当模板使 good #include<iostream> #include<string.h> #include< ...
随机推荐
- Zabbix中使用ICMP ping来判断主机是否存活的问题
上一节配置了Simple check,现在来通过Simple check 用ICMP ping来监控充节点运行情况.Zabbix使用fping处理ICMP ping的请求,需要安装fping程序,安装 ...
- android 中的几种目录
1. context.getExternalFilesDir() ==> /sdcard/Android/data/<package_name>/files/ 一般放一些长时 ...
- Yahoo! s4和Twitter storm的粗略比较
- Oracle存储过程单步调试方法
oracle存储过程单步调试的方法 1.在要调试的过程上单击test,如下图所示: 2.出现如下界面时单击最左上方的按钮:,如下图所示: 3.单击后呈现如下画面: 其中: 表示要停止test; 表示要 ...
- 20145227 《Java程序设计》实验五实验报告
20145227 <Java程序设计>实验五实验报告 实验内容 1.掌握Socket程序的编写: 2.掌握密码技术的使用: 3.设计安全传输系统. 实验过程 1.先运行TCP代码,一人服务 ...
- hihoCoder 搜索一·24点
题目1 : 搜索一·24点 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 周末,小Hi和小Ho都在家待着.在收拾完房间时,小Ho偶然发现了一副扑克,于是两人考虑用这副扑 ...
- POJ 2406:Power Strings
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 41252 Accepted: 17152 D ...
- c# ReaderWriterLock类
先前也知道,Monitor实现的是在读写两种情况的临界区中只可以让一个线程访问,那么如果业务中存在”读取密集型“操作,就 好比数据库一样,读取的操作永远比写入的操作多.针对这种情况,我们使用Monit ...
- 2015-09-17 001 日志与对话框公用类_public
using System;using System.Data;using System.Configuration;using System.Linq;using System.Web;using S ...
- Uva 11754 Code Feat
题意概述: 有一个正整数$N$满足$C$个条件,每个条件都形如“它除以$X$的余数在集合$\{Y_1, Y_2, ..., Y_k\}$中”,所有条件中的$X$两两互质, 你的任务是找出最小的S个解. ...