• 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
  • 相关阅读:
    基于Spring+SpringMVC实现AOP日志记录功能service注入异常为null的解决办法
    关于SpringBoot项目打包没有把依赖的jar包一起打包的解决办法
    JavaFx项目打包成exe,并集成Jre,使Java项目在任意机器运行
    常用正则表达式
    SqlServer 2005及其以上版本能用的查询数据的行号
    js 中的倒计时功能
    数据库删除重复列
    【转】svn文件清除批处理工具
    JS获取当前页面名称
    sql 去除重复记录
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771542.html
Copyright © 2020-2023  润新知