Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int a,x=1,y=3,z=9,k=0,j,i=0,o;
- cin>>a;
- while(a!=x && a!=y && a!=z)
- {
- i = 0;
- int n=a;
- while(n>0)
- {
- o=n%10;
- i+=o;
- n/=10;
- }
- // cout<<i<<" ";
- while(x<a)
- {
- int l=x;
- k = 0;
- while(l>0)
- {
- j=l%10;
- k+=j;
- l/=10;
- }
- x+=k;
- }
- while(y<a)
- {
- int l=y;
- k = 0;
- while(l>0)
- {
- j=l%10;
- k+=j;
- l/=10;
- }
- y+=k;
- }
- while(z<a)
- {
- int l=z;
- k = 0;
- while(l>0)
- {
- j=l%10;
- k+=j;
- l/=10;
- }
- z+=k;
- }
- if(a==x || a==y || a==z)
- {
- break;
- }
- a+=i;
- }
- if(a == x) {
- cout << 1 << " " << x;
- }
- if(a == y) {
- cout << 3 << " " << y << endl;
- }
- if(a == z) {
- cout << 9 << " " << z << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement