码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 490C Hacking Cypher

时间:2015-08-30 21:15:13      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:

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\n");
44             for(i=0;i<pos;i++)
45                 printf("%c",num[i]);
46             printf("\n");
47             for(i=pos;i<l;i++)
48                 printf("%c",num[i]);
49             printf("\n");
50         }
51         else
52             printf("NO\n");
53     }
54     return 0;
55 }
View Code

 

CodeForces 490C Hacking Cypher

标签:

原文地址:http://www.cnblogs.com/cyd308/p/4771542.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!