[ create a new paste ] login | about

Link: http://codepad.org/fbk3TGxx    [ raw code | output | fork ]

C++, pasted on Sep 11:
    unsigned long int power[11];

    bool ispal(unsigned long long int x){
        unsigned long long int rev=0,ox=x;
        while(x>0){
            rev=rev*(unsigned long long int)10+x%10;
            x/=10;
        }
        return rev==ox;
    }
    
    int superpalindromesInRange(string l, string r) {
        unsigned long long int L,R;
        L=stoll(l);
        R=stoll(r);
        power[0]=1;
        for(unsigned long int i=1;i<11;i++)
            power[i]=power[i-1]*(unsigned long long int)10;
        vector <unsigned long int> res[11];
        for(int i=0;i<=10;i++)
            res[1].push_back(i);
        for(int i=1;i<=10;i++)
            res[2].push_back(i*10+i);
        for(int i=3;i<=10;i++){
            for(int j=0;j<res[i-2].size();j++){
                for(unsigned long int k=1;k<=9;k++){
                    res[i].push_back(power[i-1]*k+res[i-2][j]*(unsigned long long int )10+k);
                }
            }
        }
        vector <unsigned long long int> a;
        for(int i=1;i<11;i++)
            a.insert(a.end(),res[i].begin(),res[i].end());
        sort(begin(a),end(a));
        unsigned long long int ans=0;
        for(unsigned long long int x:a){
            if(x*x>R)
                break;
            unsigned long long int y=x*x;
            if(y>=L&&y<=R){
                ans+=ispal(y);
                if(ispal(y))
                    cout<<y<<"\n";
            }
        }
        return ans;
    }


Output:
1
2
Line 3: error: ISO C++ does not support 'long long'
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: