CodeForces 490C 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 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).
Sample Input
116401024
97 1024
YES
11640
1024
284254589153928171911281811000
1009 1000
YES
2842545891539
28171911281811000
120
12 1
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的更多相关文章
- codeforces 490C. Hacking Cypher 解题报告
题目链接:http://codeforces.com/problemset/problem/490/C 题目意思:给出一个可能有10^6 位长的字符串且没有前导0的整数,问能否一分为二,使得前面的一部 ...
- 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 ...
- Codeforces Round #279 (Div. 2) C. Hacking Cypher (大数取余)
题目链接 C. Hacking Cyphertime limit per test1 secondmemory limit per test256 megabytesinputstandard inp ...
- 【Codeforces 490C】Hacking Cypher
[链接] 我是链接,点我呀:) [题意] 让你把一个字符串分成左右两个部分 形成两个正数 使得这两个正数一个能被a整除,一个能被b整除 找到任意一个解就可以 [题解] 枚举分割的断点i 枚举的时候用同 ...
- Codeforces Round #279 (Div. 2) C. Hacking Cypher 机智的前缀和处理
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #incl ...
- cf C. Hacking Cypher
http://codeforces.com/contest/490/problem/C 题意:把一个很大的数分成两部分,前一部分可以被a整除,后一部分可以被b整除,如果存在输出这两部分,两部分都不能含 ...
- cf490 C. Hacking Cypher(无语)
http://codeforces.com/contest/490/problem/C 表示我考场上犯逗.. 这个拆成霍纳边乘边mod即可.. 为毛我考场胡思乱想? #include <cstd ...
- CodeForces 190D Non-Secret Cypher
双指针. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
随机推荐
- Logic Bist Arch
一般现在多用的都是offline BIST的架构,可以分为4大类: 1)those assume no special structure to the circuit under test; 2)t ...
- zw版【转发·台湾nvp系列例程】halcon与delphi系列例程
zw版[转发·台湾nvp系列例程]halcon与delphi系列例程 台湾nvp技术论坛,是目前halcon与delphi例程最多的网站,也是唯一成系列的, http://zip.nvp.com.tw ...
- 【crunch bang】 tint2-用来控制桌面的布局
tint2配置: #--------------------------------------------- # TINT2 CONFIG FILE #----------------------- ...
- empty()、html("")和text("")
empty().html("")和text("")在删除匹配元素内内容时是一样的.jQuery源码中实现有所不同,但效果相同.可以测试一下源码: <!DO ...
- xUtils之ViewUtil
要使用xutils,首先要导入xutils类库. 其次要添加权限: <uses-permission android:name="android.permission.WRITE_EX ...
- 鸟哥的Linux私房菜之学习shell script
运行程序的时候一般都是创建一个子程序来执行,所以子程序中的变量什么的在当前的shell下没法使用,但是如果使用source来执行就可以在当前shell下执行程序 shift 1 去掉第一个参数,后面接 ...
- sql字段类型介绍
1 表格与储存引擎 表格(table)是数据库中用来储存纪录的基本单位,在建立一个新的数据库以后,你必须为这个数据库建立一些储存资料的表格: 每一个数据库都会使用一个资料夹,这些数据库资料夹用来储存所 ...
- 将linux下的rm命令改造成移动文件至回收站【转】
转自:http://blog.csdn.net/a3470194/article/details/16863803 [-] 将linux下的rm命令改造成移动文件至回收站 将AIX下的rm命令改造成移 ...
- linux下访问中文目录文件
文件路径包含中文时,可输入部分文件名,然后按Tab键. 当路径包含中文括号时,用斜杠,如: \(….\) . 也可用 ls -li ,先查看inum(inode编号),然后再根据编号进行访问,用查找命 ...
- Java BIO、NIO、AIO-------转载
先来个例子理解一下概念,以银行取款为例: 同步 : 自己亲自出马持银行卡到银行取钱(使用同步IO时,Java自己处理IO读写). 异步 : 委托一小弟拿银行卡到银行取钱,然后给你(使用异步IO时,Ja ...