题目链接

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 (大数取余)的更多相关文章

  1. 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 ...

  2. Codeforces Round #279 (Div. 2) C. Hacking Cypher 机智的前缀和处理

    #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #incl ...

  3. Codeforces Round #534 (Div. 2) D. Game with modulo(取余性质+二分)

    D. Game with modulo 题目链接:https://codeforces.com/contest/1104/problem/D 题意: 这题是一个交互题,首先一开始会有一个数a,你最终的 ...

  4. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  5. Codeforces Round #279 (Div. 2) 题解集合

    终于有场正常时间的比赛了...毛子换冬令时还正是好啊233 做了ABCD,E WA了3次最后没搞定,F不会= = 那就来说说做的题目吧= = A. Team Olympiad 水题嘛= = 就是个贪心 ...

  6. Codeforces Round #279 (Div. 2) vector

    A. Team Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  7. 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 ...

  8. CodeForces Round #279 (Div.2)

    A: 题意: 有三个项目和n个学生,每个学生都擅长其中一个项目,现在要组成三个人的队伍,其中每个人恰好擅长其中一门,问能组成多少支队伍. 分析: 最多能组成的队伍的个数就是擅长项目里的最少学生. #i ...

  9. 【Codeforces Round#279 Div.2】B. Queue

    这题看别人的.就是那么诚实.http://www.cnblogs.com/zhyfzy/p/4117481.html B. Queue During the lunch break all n Ber ...

随机推荐

  1. Delphi 中关闭指定进程的方法

    Uses Windows, SysUtils, Tlhelp32 ; Function KillTask( ExeFileName: String ): Integer ; //关闭进程 Functi ...

  2. NTFS文件系统的主要优点体现在以下三个方面

    1.NFTS格式具有用户权限的控制管理功能 2.NTFS有更好的压缩率 3.NTFS具有日志功能,可以提高系统安全性

  3. HTML5坦克大战1

    在JavaScript中,不要在变量为定义之前去使用,这样很难察觉并且无法运行. 颜色不对. 当我的坦克移动时,敌人坦克消失. tankGame3.html <!DOCTYPE html> ...

  4. C# Task的用法

    C# Task 的用法 其实Task跟线程池ThreadPool的功能类似,不过写起来更为简单,直观.代码更简洁了,使用Task来进行操作.可以跟线程一样可以轻松的对执行的方法进行控制. 顺便提一下, ...

  5. 省选/NOI刷题Day1

    bzoj4864 Splay乱搞 bzoj3669 正解LCT,考虑上下界的spfa可过 bzoj3668 位运算 暴力 bzoj3670 KMP DP bzoj3671 含有最小的一个数的路径一定比 ...

  6. Oracle 12c 新特性之 temp undo

    Oracle 12c R1 之前,临时表生成的undo记录是存储在undo表空间里的,通用表和持久表的undo记录也是类似的.而在 12c R12 的临时 undo 功能中,临时 undo 记录可以存 ...

  7. Netty,Netty

    Windows防火墙会自动关闭空闲的TCP链接,所以Netty需要心跳,如果发现链接断开需要进行关闭Session: 怎么来理解TCP的流式传输呢? int blocksize = buffer.re ...

  8. oracle rac搭建

    (一)环境准备 主机操作系统 windows10 虚拟机平台 vmware workstation 12 虚拟机操作系统 redhat 5.5 x86(32位) :Linux.5.5.for.x86. ...

  9. HDOJ1181(简单DFS)(练习使用STL)

    #include<iostream> #include<cstdio> #include<string> #include<map> #include& ...

  10. HDOJ1213(并查集)

    set容器中的值互异,非常好用. 水题,直接贴代码了 #include<iostream> #include<cstdio> #include<set> using ...