P1151 child integer, p1151 integer
Description
For a five-digit a1a2a3a4a5, you can split it into three child numbers:
Sub1 = a1a2a3
Sub2 = a2a3a4
Sub3 = a3a4a5
For example, a five-digit 20207 can be split
Sub1= 202
Sub2 = 020 (= 20)
Sub3 = 207
Given a positive integer K, you must program to find all the five digits that meet the following conditions between 10000 and 30000, with the condition that the three sub-numbers of these five digits sub1, sub2, sub3 can be divisible by K.
Input/Output Format
Input Format:
Input is input by the keyboard. Only one line is entered, which is a positive integer K.
Output Format:
Output to the file. Each line of the output file is a five-digit meeting the conditions, which must be output from small to large. Repeated output or omission is not allowed. If No solution is available, "No" is output ".
Input and Output sample input sample #1:
15
Output sample #1:
22555255552855530000
Description
0 <K <1000
Daily questions,
For each number, just split it!
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<queue> 6 using namespace std; 7 const int MAXN=200001; 8 const int INF = 1e8; 9 inline void read(int &n)10 {11 char c='+';int x=0;bool flag=0;12 while(c<'0'||c>'9'){c=getchar();if(c=='-')flag=1;}13 while(c>='0'&&c<='9'){x=x*10+c-48;c=getchar();}14 n=flag==1?-x:x;15 }16 int a[6];17 int main()18 {19 int n;read(n);bool flag=0;20 for(int i=10000;i<=30000;i++)21 {22 int p=i,tot=0;23 while(p) a[++tot]=p%10,p/=10;24 if((((a[1]+a[2]*10+a[3]*100)%n)==0)&&(((a[2]+a[3]*10+a[4]*100)%n)==0)&&(((a[3]+a[4]*10+a[5]*100)%n)==0))25 printf("%d\n",i),flag=1;26 }27 if(flag==0)cout<<"No";28 return 0;29 }