zoukankan      html  css  js  c++  java
  • Codeforces 490C 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 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 <iostream>
    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <cmath>
    #include <vector>
    #include <queue>
    #include <map>
    #include <set>
    #include <stack>
    #include <algorithm>
    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 10000
    
    char 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
    only strive for your goal , can you make your dream come true ?
  • 相关阅读:
    分享一个自己写的vue多语言插件smart-vue-i18n
    利用vw+rem实现移动web适配布局
    你说前端不了解业务?
    小程序开发总结一:mpvue框架及与小程序原生的混搭开发
    小码农的职场人生一:由张小平离职引发的一些吐槽
    javascript本地缓存方案-- 存储对象和设置过期时间
    手淘移动适配方案flexible.js兼容bug处理
    微信小程序入坑之自定义组件
    vuejs开发组件分享之H5图片上传、压缩及拍照旋转的问题处理
    非域环境下使用证书部署数据库(SqlServer2008R2)镜像
  • 原文地址:https://www.cnblogs.com/hlmark/p/4117544.html
Copyright © 2011-2022 走看看