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 ...
随机推荐
- 夺命雷公狗—angularjs—15—内置封装好的计时器$interval和$timeout
这里其实和js源生的效果是一样的,但是源生的在angularjs里面不能直接正常执行代码如下所示: <!DOCTYPE html> <html lang="en" ...
- 《zw版·Halcon-delphi系列原创教程》 3d汽车模型自动区域分割
<zw版·Halcon-delphi系列原创教程> 3d汽车模型自动区域分割 目前,图像分析,在3D设计,机器视觉方面拥有很广.这个Halcon脚本是3d汽车模型自动区域分割,很简单才20 ...
- 【py网页】urllib.urlretrieve远程下载
下面我们再来看看 urllib 模块提供的 urlretrieve() 函数.urlretrieve() 方法直接将远程数据下载到本地. 1 >>> help(urllib.urlr ...
- JS中数组的操作
1.数组的创建 var arrayObj = new Array(); //创建一个数组 var arrayObj = new Array([size]); //创建一个数组并指定长度,注意不是上限, ...
- java中的拷贝(二)深克隆
浅拷贝(Object类中的clone()方法)是指在拷贝对象时,对于基本数据类型的变量会重新复制一份,而对于引用类型的变量只是对引用进行拷贝. 深拷贝(或叫深克隆) 则是对对象及该对象关联的对象内容, ...
- YUI Reset CSS (学习摘抄)
正在使用CSS的你,用过CSS Reset吗?当然,或许你用了,却不知道正在用,比如你可能用到: *{ margin: 0; border: 0; padding: 0; } 这 ...
- 视频处理控件TVideoGrabber中如何混合多个视频源(1)
其实一个或是几个作为普通的视频源使用的TVideoGrabber组件,可以进行混合来作为一个TVideoGrabber组件使用,这些普通的组件可以是视频捕捉设备或是视频剪辑等.同时这个混合的组件独立于 ...
- 将edit ctrL弄的像个dos
case WM_CTLCOLOREDIT: { HWND hShellText = GetDlgItem(hDlg,IDC_TXT_SHELL); if (hShellText == (HWND)lP ...
- init_MUTEX 与 sema_init 函数【转】
转自:http://blog.chinaunix.net/uid-7332782-id-3211627.html 在编译Linux设备驱动程序学习(1)-字符设备驱动程序中scull.c程序时,报错: ...
- Java常用jar包用途
Java常用jar包用途: USAGE INDEX JAR NAME USAGE 1 ASM asm-2.2.3.jar ASM字节码库 2 ASM asm-commons-2.2.3.jar ASM ...