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 ...
随机推荐
- JFreeChart在制作折线图
JFreeChart在制作折线图的时候可以使用两种不同的方式 package Line; import java.awt.Color; import java.awt.Font; import org ...
- 分层导航and隐藏导航
一.分层导航 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...
- [tp3.2.1]大D构建模型
使用大(写字母)D方法: 如果,在默认到Home模块下面找不到UserModel模块,那么就会到Common模块下去找. 而如果此时在Common模块下还是找不到UserModel,那就会调用Mode ...
- UINavigationController详解一(转)UIBarButtonItem
本文出自:http://www.cnblogs.com/smileEvday/archive/2012/05/14/2495153.html 特别感谢. 1.UINavigationControlle ...
- dir cmd、the DIR Command、windows
原因 :如何在windows下的cmd.exe中只列出文件名? solve : dir \a:-d \b Extend Reading : dir [drive:][path][filename] ...
- Bootstrap:弹出框和提示框效果以及代码展示
前言:对于Web开发人员,弹出框和提示框的使用肯定不会陌生,比如常见的表格新增和编辑功能,一般常见的主要有两种处理方式:行内编辑和弹出框编辑.在增加用户体验方面,弹出框和提示框起着重要的作用,如果你的 ...
- Base Enum Properties [AX 2012]
Base Enum Properties [AX 2012] This topic has not yet been rated - Rate this topic Updated: December ...
- expdp impdp中 exclude/include 的使用
exclude和include参数能够在使用expdp或impdp是对特定的对象或对象类型进行筛选或过滤.比如因工作的需要导出特定的表或不导出特定 的表.视图以及存储过程.索引.约束.授权统计信息等等 ...
- hdwik中view模块的应用
概述 MVC中的视图view 主要负责页面显示部分,所有的页面显示全部在此实现,视图对整个页面负责,它通过control的调用来显示页面和数据.视图(view)类template.cla ...
- java面试每日一题5
题目:企业发放的奖金根据利润提成.利润(I)低于或等于10万元时,奖金可提10%:利润高于10万元,低于20万元时,低于10万元的部分按10%提 成,高于10万元的部分,可可提成7.5%:20万到40 ...