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 input
output
standard output
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 test(s)
input
116401024
97 1024
output
YES
11640
1024
input
284254589153928171911281811000
1009 1000
output
YES
2842545891539
28171911281811000
input
120
12 1
output
NO
题意:一个很大的数,可能有10^6位,给两个数字a,b 求把给的大数分为两部分,如果这两部分
能分别整除a,b,且没有前导0,输出YES,否则输出NO.
分析:大数取余。
正着一遍a, 倒着一遍b。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <map>
#include <vector>
#include <algorithm>
#define LL __int64
const int maxn = 1e6 + ;
using namespace std;
char s[maxn];
int f1[maxn], f2[maxn]; int main()
{
int a, b, i, len;
int tmp, tmp2, x;
int y;
while(~scanf("%s", s))
{
scanf("%d%d", &a, &b);
memset(f1, , sizeof(f1));
memset(f2, , sizeof(f2));
len = strlen(s);
tmp2 = ;
for(i = ; i < len; i++)
{
tmp = (s[i]-)%a;
tmp2 = ((tmp2*)+tmp)%a;
if(tmp2==) f1[i] = ;
} tmp2 = ; x = ;
for(i = len-; i >= ; i--)
{
tmp = (s[i]-)%b;
tmp = (tmp*x)%b;
tmp2 = (tmp2 + tmp)%b;
if(tmp2 == ) f2[i] = ;
x = (x*)%b;
} y = -;
for(i = ; i < len-; i++)
{
if(f1[i]&&f2[i+] && s[i+]!='')
{
y = i;
break;
}
}
if(y==-)
cout<<"NO"<<endl;
else
{
cout<<"YES"<<endl;
for(i = ; i <= y; i++)
printf("%c", s[i]);
cout<<endl;
for(; i < len; i++)
printf("%c", s[i]);
cout<<endl;
}
}
return ;
}
Codeforces Round #279 (Div. 2) C. Hacking Cypher (大数取余)的更多相关文章
- 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 机智的前缀和处理
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #incl ...
- Codeforces Round #534 (Div. 2) D. Game with modulo(取余性质+二分)
D. Game with modulo 题目链接:https://codeforces.com/contest/1104/problem/D 题意: 这题是一个交互题,首先一开始会有一个数a,你最终的 ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #279 (Div. 2) 题解集合
终于有场正常时间的比赛了...毛子换冬令时还正是好啊233 做了ABCD,E WA了3次最后没搞定,F不会= = 那就来说说做的题目吧= = A. Team Olympiad 水题嘛= = 就是个贪心 ...
- Codeforces Round #279 (Div. 2) vector
A. Team Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #279 (Div. 2) E. Restoring Increasing Sequence 二分
E. Restoring Increasing Sequence time limit per test 1 second memory limit per test 256 megabytes in ...
- CodeForces Round #279 (Div.2)
A: 题意: 有三个项目和n个学生,每个学生都擅长其中一个项目,现在要组成三个人的队伍,其中每个人恰好擅长其中一门,问能组成多少支队伍. 分析: 最多能组成的队伍的个数就是擅长项目里的最少学生. #i ...
- 【Codeforces Round#279 Div.2】B. Queue
这题看别人的.就是那么诚实.http://www.cnblogs.com/zhyfzy/p/4117481.html B. Queue During the lunch break all n Ber ...
随机推荐
- EntityFramework 学习 一 DbSet
DBSet类表示一个实体的集合,用来创建.更新.删除.查询操作,DBSet<TEntity>是DBSet的泛型版本 你可以使用DbContext获取DBSet的引用,例如dbContext ...
- Quota Management and Enforcement
Neutron API中大多的resource都需要quota limits. Neutron API暴露出一个extension 来管理quota,Quota limits are enforced ...
- java:stack栈: Stack 类表示后进先出(LIFO)的对象堆栈
//Stack 类表示后进先出(LIFO)的对象堆栈 //它提供了通常的 push 和 pop 操作,以及取栈顶点的 peek 方法.测试堆栈是否为空的 empty 方法.在堆栈中查找项并确定到栈顶距 ...
- 为什么jdk1.8不支持sql.append,该如何解决
StringBuilder sql = new StringBuilder("SELECT ID,COMMAND,DESCRIPTION,CONTENT FROM message where ...
- JVM的性能跳优
首先需要找到需要进行调优的进程. 通过jps -v -l -m 找到我需要调优的进程 其中, -m表示输出传入main方法的参数, -l表示输出的main类或jar包的名字, -v表示传入JVM的参数 ...
- codeforces 86D D. Powerful array(莫队算法)
题目链接: D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input stan ...
- Java中的泛型、枚举和注解
1.泛型: 一.为什么要有泛型(Generic)?1.解决元素存储的安全性问题任何类型都可以添加到集合中:类型不安全2.解决获取数据元素时,需要类型强转的问题读取出来的对象需要强转:繁琐可能有Clas ...
- I.MX6 FFmpeg 录制视频
/************************************************************************* * I.MX6 FFmpeg 录制视频 * 说明: ...
- 小程序wxss编译错误
控制台输入openVendor() ,清除里面的wcsc.exe,然后重启工具.
- hdu 3998 Sequence
There is a sequence X (i.e. x[1], x[2], ..., x[n]). We define increasing subsequence of X as x[i1], ...