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. 夺命雷公狗---Thinkphp----1之目录介绍

    ThinkPHP框架 特点: 免费开源 敏捷开发(快速开发) 面向对象 MVC思想 yii,ci之类的框架都有这些特点.是06年到现在的一个老牌框架,现在还是个很不错的框架 可以在thinkphp的官 ...

  2. [Ubuntu] ubuntu13.04 从php5.4降级到php5.3

    ubuntu12.10以后,默认的deb安装库上面的php版本已经是5.4了,公司的项目使用5.4的时候,还是会出现很多问题,所以不得不降级安装5.3 顺便说一句,我原来的环境是nginx + php ...

  3. 《聚焦3D地形编程》学习点

    痞子龙的译本虽然称不上好,但却保留了原汁原味,看这本书时最好结合原文与痞子龙的译文.另外,如果有过地形生成的经验再看这本书时有些帮助,这本书介绍的专业的室外地形开发,很全面的介绍. 仅是个人总结,可能 ...

  4. Java简单数据类型转换

      1. Integer<---String   (1) Integer x = new Integer(Integer.parseInt(String)); 2. Integer<--- ...

  5. composer未升级报错

    错误: Cannot adopt OID in SQUID-MIB: cacheClients ::= { cacheProtoAggregateStats 15 } Cannot adopt OID ...

  6. vm克隆虚拟机网络配置

    *CentOS虚拟机网络连接方式为:桥接模式* 虚拟机克隆后会导致网络连接不上:(引起原因是新的MAC和网卡配置对应不上)问题解决(在克隆机里执行下列步骤): vi /etc/udev/rules.d ...

  7. python 路径

    atm---main.py import os ,sys print(__file__) print(os.path.abspath(__file__))#绝对路径 print(os.path.dir ...

  8. ThinkPHP使用PHPmailer发送Email邮件

    下面介绍thinkphp如何使用phpmailer发送邮件,使用这个邮件发送类,配置好参数后,一句话即可发送邮件.仅适合于thinkphp框架. 第一步,下载类库 将Mail.class.php复制到 ...

  9. 批量解密SQLSERVER数据库中的各种对象的工具dbForge SQL Decryptor2.1.11

    参考地址: http://www.cnblogs.com/lyhabc/p/3505677.html SQLPROMPT5.3对各种加密对象的解密测试 SQL2005解密已经被加密的存储过程 昨天ah ...

  10. sscanf 函数 分类: POJ 2015-08-04 09:19 4人阅读 评论(0) 收藏

    sscanf 其实很强大 分类: 纯C技术 技术笔记 2010-03-05 16:00 12133人阅读 评论(4) 收藏 举报 正则表达式stringbuffercurlgoogle 最近在做日志分 ...