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 ...
随机推荐
- hiho一下 第四十九周 题目1 : 欧拉路·一【无向图 欧拉路问题】
题目1 : 欧拉路·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho最近在玩一个解密类的游戏,他们需要控制角色在一片原始丛林里面探险,收集道具,并找到最 ...
- hihocoder第七周 完全背包模板题
时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 且说之前的故事里,小Hi和小Ho费劲心思终于拿到了茫茫多的奖券!而现在,终于到了小Ho领取奖励的时刻了! 等等,这段故事为 ...
- 针对PHP性能方面编程技巧的总结
注:本文为作者多年工作经验总结,转贴请注明出处 Albert Wang 做PHP已经有4年多了吧,总是没写点什么总结一下,现在开始写博客了,也顺便总结下吧,留给那些新入行的朋友看看. 1. 不宜频繁使 ...
- php一维数组的创建
php一维数组的创建 (1)通过array函数声明数组 使用array 函数定义数组,该函数返回通过所接受接收的参数建立的数组.array 函数使用的格式如下. $arry_name = array( ...
- BZOJ 1597 [Usaco2008 Mar]土地购买:斜率优化dp
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1597 题意: 有n块矩形土地,长为a[i],宽为b[i]. FJ想要将这n块土地全部买下来 ...
- 初步认识Express框架渲染视图
给出一个简单的例子,讲述模板渲染的基础功能 在nodejs中使用express框架,默认的是ejs和jade渲染模板,以下是以ejs模板进行解析 1.ejs 模板安装 npm install ejs ...
- Linux课程---8、Linux启动流程
Linux课程---8.Linux启动流程 一.总结 一句话总结: grub启动引导界面(比如装了多系统,选择系统),找到linux内核 启动init程序,加载各种驱动 1.进入grub界面选择相应的 ...
- Selenium-浮层的操作
实现-百度登录浮层-输入登录用户名 #! /usr/bin/env python #coding=utf-8 ''' 百度首页-登录浮层 ''' from selenium import webdri ...
- JSTL1.0 知识回顾与总结
JSTL1.0,由四个定制标志库(core,format,xml和sql) 和一对通用标记库验证器(ScriptFreeTLV 和 PermittedTaglibsTLV )组成. 1.基本输出设置操 ...
- ACM学习历程—HDU4675 GCD of Sequence(莫比乌斯)
Description Alice is playing a game with Bob. Alice shows N integers a 1, a 2, …, a N, and M, K. She ...