Skip to content

Instantly share code, notes, and snippets.

@zuigon
Created May 19, 2010 18:54
Show Gist options
  • Save zuigon/406693 to your computer and use it in GitHub Desktop.
Save zuigon/406693 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
// niz.cpp
// unos: m, n :(int)
// ispis: n-ti broj sa brojem znamenaka 4*m
int sumzn(int x){
int sum=0,orig=x;
while(x!=0){ sum+=x%10; x/=10; }
//cout<<"sumzn("<<orig<<") = "<<sum<<endl;
return sum;
}
int main(){
/*
cout << "TEST:"<<endl;
cout << "sumzn(1): "<<sumzn(1)<<endl;
cout << "sumzn(12): "<<sumzn(12)<<endl;
cout << "sumzn(123): "<<sumzn(123)<<endl;
cout << "sumzn(12345678): "<<sumzn(12345678)<<endl;
cout << "------------------------"<<endl;
*/
int m,n,
t,s,tt;
cin>>m>>n;
t=m+1; s=sumzn(4*m);
t=1;
//if(n==1){ cout<<}
for(int i=1; i<n; i++){
while(sumzn(t)!=s) t++; s=sumzn(t*4);
if(i==n-1) cout<<t<<endl;
t=s;
//cout<<" - after while... t="<<t<<endl;
}
//cout << "t: "<<t<<endl;
//cout << "tt: "<<tt<<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment