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 ?
  • 相关阅读:
    ckplayer不支持谷歌92版本,flashplayer不支持m3u8的方案
    git merge 失败
    在SuperSocket中使用Unity注入
    在WPF中集成SuperSocket 2.0
    在WPF中打印A4纸
    使用 HoloLens 仿真器
    C# 优化内存和运行效率
    Redis 高可用篇:你管这叫 Sentinel 哨兵集群原理
    Redis 核心篇:唯快不破的秘密
    Redis 日志篇:无畏宕机快速恢复的杀手锏
  • 原文地址:https://www.cnblogs.com/hlmark/p/4117544.html
Copyright © 2011-2022 走看看