Find all number pairs that sum to 121212
C++

#include&lt;iostream&gt;
using namespace std;
#include&lt;algorithm&gt;

int main()
{
    long long N,F,S;
    char str[11]="1023456789";
    while (1) {
        sscanf(str,"%lld",&amp;N);
        F=N/100000;S=N%100000;
        if (F&gt;60000)
           break;
        if (F+S==121212)
           printf("%lld %lld\n",F,S);
        next_permutation(str,str+10);
    }
}


http://www.ideone.com/Lr84g