Codeforces Round #279 (Div. 2) C. Hacking Cypher 前缀+后缀

时间:2023-02-05 10:07:33
C. Hacking Cypher
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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).

Output

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).

Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
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 前缀+后缀的更多相关文章

  1. Codeforces Round &num;279 &lpar;Div&period; 2&rpar; C&period; Hacking Cypher (大数取余)

    题目链接 C. Hacking Cyphertime limit per test1 secondmemory limit per test256 megabytesinputstandard inp ...

  2. Codeforces Round &num;279 &lpar;Div&period; 2&rpar; C&period; Hacking Cypher 机智的前缀和处理

    #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #incl ...

  3. Codeforces Round &num;279 &lpar;Div&period; 2&rpar; ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  4. Codeforces Round &num;279 &lpar;Div&period; 2&rpar; 题解集合

    终于有场正常时间的比赛了...毛子换冬令时还正是好啊233 做了ABCD,E WA了3次最后没搞定,F不会= = 那就来说说做的题目吧= = A. Team Olympiad 水题嘛= = 就是个贪心 ...

  5. Codeforces Round &num;279 &lpar;Div&period; 2&rpar; vector

    A. Team Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  6. Codeforces Round &num;279 &lpar;Div&period; 2&rpar; E&period; Restoring Increasing Sequence 二分

    E. Restoring Increasing Sequence time limit per test 1 second memory limit per test 256 megabytes in ...

  7. CodeForces Round &num;279 &lpar;Div&period;2&rpar;

    A: 题意: 有三个项目和n个学生,每个学生都擅长其中一个项目,现在要组成三个人的队伍,其中每个人恰好擅长其中一门,问能组成多少支队伍. 分析: 最多能组成的队伍的个数就是擅长项目里的最少学生. #i ...

  8. 【Codeforces Round&num;279 Div&period;2】B&period; Queue

    这题看别人的.就是那么诚实.http://www.cnblogs.com/zhyfzy/p/4117481.html B. Queue During the lunch break all n Ber ...

  9. Codeforces Round &num;279 &lpar;Div&period; 2&rpar;f

    树形最大上升子序列 这里面的上生子序列logn的地方能当模板使  good #include<iostream> #include<string.h> #include< ...

随机推荐

  1. SecureCRT中设置 &bsol;n 为回车换行,和 &bsol;r&bsol;n 的行为一致

    勾上途中红框的选项即可

  2. j2ee log4j集中式日志解决方案logpool v0&period;3

    V0.3相对于v0.2的更新如下:

  3. anr产生的原理&amp&semi;如何避免&lpar;android&rpar;

  4. Jeally Bean中MonekyRunner 帮助文件

    基于4.2的SDK导出来的MonkeyRunner的最新帮助,这个版本对MonkeyView和MonkeyRect有了很大的加强,在MonkeyRunner的易用性上有了很大的提高. 对于导出Monk ...

  5. template&lowbar;11实参演绎

    1,演绎过程匹配类型A(来自实参的类型),参数化类型P(行参参数声明)如果被声明的参数是一个引用声明g(T& )那么P就是所引用类型T:f(T)中P就是所声明的参数类: decay指从数组和函 ...

  6. jsp servelet

    servlet是java web应用程序. 1.生命周期:init() .service().destroy()方法. 其中service()包括 doGet() .doPost()方法.默认为get ...

  7. Android新建项目手动添加Layout布局

    前言: 这是看<第一行代码>学习到的第一章,之前使用Eclipse创建Android项目都是自动生成MainActivity.java文件和layout文件夹下的activity_main ...

  8. 201521123015 《Java程序设计》第2周学习总结

    1.本章学习总结 (1)学习了枚举,数组等方法 (2)通过实验内容的讲解,解决了一些问题 (3)进一步运用和了解码云 书面作业 1.使用Eclipse关联jdk源代码,并查看String对象的源代码( ...

  9. 部署crm项目

    准备工作 使用xftp将项目传到linux 将knight 传到linux上 将项目的数据导出 mysqldum -uroot -p --all-database > alldb.dump 在w ...

  10. python笔记11-元组

    lis = ['127.0.0.1','3306']#列表tp = ('127.0.0.1','3306') #定义元组 lis[1]='3307'print(lis)print(tp[0])元祖也有 ...