project euler 62 Cubic permutations

#include <bits/stdc++.h>
using namespace std;
#define BUFF ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define ll long long
inline ll read(){ll f=1;ll x=0;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();return x*f; }
inline ll quick_pow(ll a,ll b,ll mod) {ll ans=1,base=a;while(b){if(b&1)ans=ans*base%mod;base=base*base%mod;b>>=1;}return ans%mod;}
inline ll inv(ll x,ll p){return quick_pow(x,p-2,p);}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const double pi=acos(-1.0);
const ll inf = LONG_LONG_MAX;
const ll mod = 1e9+7;
const ll maxn = 1000;
map<vector<int>, vector<int> > mp;
vector<int> work(ll num)
{
    vector<int>v;
    while(num)
    {
        v.push_back(num % 10);
        num /= 10;
    }
    sort(v.begin(), v.end());
    return v;
}
int main()
{
    mp.clear();
    ll cnt = 1;
    while(cnt != 10000)
    {
        vector<int> v = work(pow(cnt, 3));
        mp[v].push_back(cnt);
        cnt++;
    }
    for(auto &&it:mp)
    {
        if(it.second.size() == 5)
        {
            for(auto i:it.second)
            {
                cout << i <<" ";
            }
            sort(it.second.begin(), it.second.end());
            cout << (ll)pow(*it.second.begin(), 3) << '\n';
        }
    }
    return 0;
}

上一篇:索尼第三财季净利润35.42亿美元,同比增长62%


下一篇:leetcode-剑指62-OK