zoukankan      html  css  js  c++  java
  • CodeForces 490C Hacking Cypher

    Hacking Cypher
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    Description

    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 Input

    Input
    116401024
    97 1024
    Output
    YES
    11640
    1024
    Input
    284254589153928171911281811000
    1009 1000
    Output
    YES
    2842545891539
    28171911281811000
    Input
    120
    12 1
    Output
    NO
     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 char num[1000010];
     5 int c[1000010];
     6 
     7 int main()
     8 {
     9     int i,j,a,b;
    10     int flg;
    11     while(scanf("%s",num)!=EOF)
    12     {
    13         flg=0;
    14         scanf("%d %d",&a,&b);
    15         memset(c,0,sizeof(c));
    16         int l=strlen(num);
    17         int cur = 0;
    18         for(i=0; i<l; i++)
    19         {
    20             cur *= 10;
    21             cur += num[i]-'0';
    22             cur %= a;
    23             if(cur==0 && i<l-1 && num[i+1]!='0')
    24                 c[i] = 1;
    25         }
    26         int k=1, pos;
    27         cur = 0;
    28         for(i=l-1;i>=0; i--)
    29         {
    30             cur+=(num[i]-'0')*k;
    31             cur%=b;
    32             if(cur==0 && c[i-1] &&num[i]!='0')
    33             {
    34                 flg=1;
    35                 pos=i;
    36                 break;
    37             }
    38             k*=10;
    39             k%=b;
    40         }
    41         if(flg)
    42         {
    43             printf("YES
    ");
    44             for(i=0;i<pos;i++)
    45                 printf("%c",num[i]);
    46             printf("
    ");
    47             for(i=pos;i<l;i++)
    48                 printf("%c",num[i]);
    49             printf("
    ");
    50         }
    51         else
    52             printf("NO
    ");
    53     }
    54     return 0;
    55 }
    View Code
  • 相关阅读:
    读写ini文件
    身份证号码验证正则表达式
    使用SubSonic生成数据访问层步骤
    MonoRail&ActiveRecord开发中的注意事项
    C#实现邮件发送的功能
    建立ASP.NET服务器控件
    操作身份验证
    看了几天C#了...人开始变得有点急躁
    关于正则表达式
    如何在多台电脑上同时安装Windows
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771542.html
Copyright © 2011-2022 走看看