博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 490C Hacking Cypher
阅读量:7210 次
发布时间:2019-06-29

本文共 3670 字,大约阅读时间需要 12 分钟。

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 ab (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 给出一个长度为1e6的数你 , 然后两个数 a , b 最大是1e8 。 问能否把 第一个数切成2半 ,然后半部分整除 a  , 后半部分整除 b 。 想了挺久 。 一开始以为要大数。 其实不然 。 对于一个数 a , 在最后加一个个位数 b 的话 : ( a*10 + b ) % mod = ( ( a % mod ) * ( 10 % mod ) % mod + b % mod ) % mod ; 然而 , 在最前面加的话 。 按上面的公式可以求出 10^i % mod 的值, 所以又知道 ( b * 10^i ) % mod 的值 。 那么 ( b*10^i + a )% mod  又可以求出来了。 若果余数是0的话就可以整除了 。 在判断一下有没有前缀0即可
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long LL;const int N = 1000010;const int inf = 1e7+7;const double PI = acos(-1.0);const double eps = 1e-6 ;#define base 10000char str[N];int num[N] ;LL a , b , len ;bool can1[N] , can2[N];void run() { for( int i = 0 ; i + 1 < len ; ++i ) if( can1[i] && can2[i+1] && num[i+1] ){ cout << "YES" << endl ; for( int j = 0 ; j <= i ; ++j ) cout << str[j] ; cout << endl ; for( int j = i + 1 ; j < len ; ++j ) cout << str[j] ; cout << endl ; return ; } cout << "NO" << endl ;}int main(){ #ifdef LOCAL freopen("in.txt","r",stdin); #endif // LOCAL ios::sync_with_stdio(false); while( scanf("%s",str) != EOF ) { scanf("%d%d",&a,&b); memset( can1 , false , sizeof can1 ); memset( can2 , false , sizeof can2 ); len = strlen( str ); for( int i = 0 ; i < len ; ++i ) num[i] = str[i] - '0' ; LL num1 = 0 ; for( int i = 0 ; i < len ; ++i ){ num1 = ( ( ( num1 % a ) * ( 10 % a ) ) % a + num[i] % a ) % a ; if( !num1 ) can1[i] = true ; } LL num2 = 0 , num3 = 1 ; for( int i = len -1 ; i >= 0 ; --i ){ LL temp = ( num3 * num[i] ) % b ; num2 = ( temp + num2 ) % b ; if( !num2 ) can2[i] = true ; num3 = num3 * ( 10 % b ) % b ; } run(); }}
View Code

 

转载于:https://www.cnblogs.com/hlmark/p/4117544.html

你可能感兴趣的文章
《C++面向对象高效编程(第2版)》——3.16 从函数中返回引用
查看>>
《JavaScript精粹(修订版)》——1.6 使用括号和分号结束符(一致的编码方式)...
查看>>
2.4 表单数据的验证
查看>>
《Android游戏开发详解》——第2章,第2.10节使用对象
查看>>
《OpenGL ES 2.0游戏开发(上卷):基础技术和典型案例》一第6章 让场景更逼真——光照效果...
查看>>
MongoDB介绍与安装
查看>>
《C语言接口与实现:创建可重用软件的技术》一1.5 习题
查看>>
《网页设计与前端开发 Dreamweaver+Flash+Photoshop+HTML+CSS+JavaScript 从入门到精通》—— 第1章 网页设计基础知识...
查看>>
Maven实战. 3.7NetBeans Maven插件简单使用
查看>>
Android开发技术周报 Issue#17
查看>>
《iOS 9 开发指南》——第6章,第6.7节iOS 9控件的属性
查看>>
this is incompatible with sql_mode=only_full_group_by
查看>>
TableView编辑状态下跳转页面的崩溃处理
查看>>
java操作阿里云的对象存储OSS
查看>>
linux 如何判断当前用户
查看>>
ERROR 1045 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: YES)
查看>>
魔兽世界客户端数据研究(四):M2文件头分析
查看>>
jQuery中getJSON跨域原理详解
查看>>
【MySql】MySql存储,游标,循环的简单使用
查看>>
一些服务器客户端的c例子
查看>>