Hacking Cypher

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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 to106 digits. The second line contains a pair of space-separated positive integers ab (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).

Sample Input

Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
 #include <stdio.h>
#include <string.h> char num[];
int c[]; int main()
{
int i,j,a,b;
int flg;
while(scanf("%s",num)!=EOF)
{
flg=;
scanf("%d %d",&a,&b);
memset(c,,sizeof(c));
int l=strlen(num);
int cur = ;
for(i=; i<l; i++)
{
cur *= ;
cur += num[i]-'';
cur %= a;
if(cur== && i<l- && num[i+]!='')
c[i] = ;
}
int k=, pos;
cur = ;
for(i=l-;i>=; i--)
{
cur+=(num[i]-'')*k;
cur%=b;
if(cur== && c[i-] &&num[i]!='')
{
flg=;
pos=i;
break;
}
k*=;
k%=b;
}
if(flg)
{
printf("YES\n");
for(i=;i<pos;i++)
printf("%c",num[i]);
printf("\n");
for(i=pos;i<l;i++)
printf("%c",num[i]);
printf("\n");
}
else
printf("NO\n");
}
return ;
}

CodeForces 490C Hacking Cypher的更多相关文章

  1. codeforces 490C. Hacking Cypher 解题报告

    题目链接:http://codeforces.com/problemset/problem/490/C 题目意思:给出一个可能有10^6 位长的字符串且没有前导0的整数,问能否一分为二,使得前面的一部 ...

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

    C. Hacking Cypher time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  3. Codeforces Round #279 (Div. 2) C. Hacking Cypher (大数取余)

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

  4. 【Codeforces 490C】Hacking Cypher

    [链接] 我是链接,点我呀:) [题意] 让你把一个字符串分成左右两个部分 形成两个正数 使得这两个正数一个能被a整除,一个能被b整除 找到任意一个解就可以 [题解] 枚举分割的断点i 枚举的时候用同 ...

  5. Codeforces Round #279 (Div. 2) C. Hacking Cypher 机智的前缀和处理

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

  6. cf C. Hacking Cypher

    http://codeforces.com/contest/490/problem/C 题意:把一个很大的数分成两部分,前一部分可以被a整除,后一部分可以被b整除,如果存在输出这两部分,两部分都不能含 ...

  7. cf490 C. Hacking Cypher(无语)

    http://codeforces.com/contest/490/problem/C 表示我考场上犯逗.. 这个拆成霍纳边乘边mod即可.. 为毛我考场胡思乱想? #include <cstd ...

  8. CodeForces 190D Non-Secret Cypher

    双指针. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  9. Codeforces Round #279 (Div. 2) ABCDE

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

随机推荐

  1. Subversion简明手册--使用hook svn

    使用 hook ,为了方便管理员 控制提交的过程 Subversion 提供了 hook 机制.当特定的 事件发生时,相应的 hook 会被调用, hook 其实就相当于特定 事件的处理函数.每个 h ...

  2. 苹果系统直接读写 ntfs 磁盘

    苹果系统对 ntfs 能读,但不能写. 方案1:修改 fstab 法 ======================================== 读写支持.在使用本教学文章之前,请先确定你没有安 ...

  3. inux设备驱动归纳总结(五):2.操作硬件——IO内存【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-80627.html inux设备驱动归纳总结(五):2.操作硬件——IO内存 xxxxxxxxxxxx ...

  4. React笔记_(2)_react语法1

    这一节内容主要以了解为主. 渐渐的体会react的语法和其特性. ① htmlAndJs 混合编写 react和以往的前后台书写方式不一样. 在之前的多个语言中,讲求的是将页面代码和js代码逻辑分开, ...

  5. WINCE 隐藏标题栏

    转自:https://social.msdn.microsoft.com/Forums/en-US/cef1c20a-25cf-49b6-a56e-6bc733be88f8/removing-the- ...

  6. 【Pro ASP.NET MVC 3 Framework】.学习笔记.10.SportsStore:上传图片

    1 扩展数据库 打开表定义,新增两列可空 ) 2 增强领域模型 为Products类添加如下属性 publicstring ImageMimeType { get; set; } 第一个属性不会在界面 ...

  7. org.hibernate.TransientObjectException

    使用JPA注解@ManyToMany做一个多对多的用例. 为了避免在删除主表数据时同时级联删除从表数据,JPA官方文档建议在主表的从表字段使用级联注解:CascadeType.PERSIST,Casc ...

  8. webservice cxf error:org.apache.cxf.interceptor.Fault: Unmarshalling Error: 意外的元素 (uri:"", local:"ca

    服务器端webservice接口 需要定义@WebParam,如: public ReturnDTO cardBatchSyn(@WebParam(name = "cardBatchSynM ...

  9. Python入门学习笔记

    了解 一下Python中的基本语法,发现挺不适应的,例如变量经常想去指定类型或者if加个括号之类的.这是在MOOC中学习到的知识中一点简单的笔记. Python的变量和数据类型: 1.Python这种 ...

  10. Spring声明式事务管理与配置详解

    转载:http://www.cnblogs.com/hellojava/archive/2012/11/21/2780694.html 1.Spring声明式事务配置的五种方式 前段时间对Spring ...