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 ?
  • 相关阅读:
    .net日期类与UNIX时间戳的相互转换,长数字
    钉钉的生日模块在哪
    js判断手机是苹果(IOS)还是安卓(android) H5手机端自适应宽高
    .net网站部署winserver2008R2 IIS只列出目录 浏览只显示目录浏览
    ajax有时请求不到数据 后台,有时收不到返回值的解决办法
    overflow不超出时不显示滚动条 属性解决内容未超出依然显示滚动条轨道的问题
    PB取datawindow生成的语句。要在datawindow的sqlpreview事件
    电脑C盘缓存路径在哪,清理C盘哪个文件夹可以删
    PB里执行写SQL语句
    SQL SERVER合并行。将多行数据合并成一行,字符串拼接
  • 原文地址:https://www.cnblogs.com/hlmark/p/4117544.html
Copyright © 2011-2022 走看看