- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####*******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define sc(n) scanf("%d", &n)
- #define S 10000003
- using namespace std;
- typedef long long LL;
- struct data{
- int Num;
- vector <int> Qube;
- }arr[S];
- int qube[S];
- int cmp(data p, data q){
- if(p.Num == q.Num)return p.Qube < q.Qube;
- return p.Num < q.Num;
- }
- void asgn_qube(){
- for(int i = 2; i <= 200; i++)qube[i*i*i] = i;
- }
- int prfct_qube(int z){
- int w, x, y;
- for(int i = 2; i <= 200; i++){
- w = i*i*i;
- for(int j = i+1; j <= 200; j++){
- x = j*j*j;
- for(int k = j+1; k <= 200; k++){
- y = k*k*k;
- if(w+x+y < S && qube[w+x+y]){
- arr[z].Num = qube[w+x+y];
- arr[z].Qube.push_back(i);
- arr[z].Qube.push_back(j);
- arr[z].Qube.push_back(k);
- z++;
- }
- }
- }
- }
- sort(arr, arr+z, cmp);
- return z;
- }
- void Do(){
- asgn_qube();
- int lim = prfct_qube(0);
- int l = 0;
- for(int i = 0; i < lim; i++){
- int sz = arr[i].Qube.size();
- cout << "Cube = " << arr[i].Num << ", ";
- for(int j = 0; j < 3; j++){
- if(!j)cout << "Triple = (";
- if(j == 2)cout << arr[i].Qube[j] << ")" << endl;
- else cout << arr[i].Qube[j] << ",";
- }
- }
- }
- int main(){
- ios_base::sync_with_stdio(0); cin.tie(0);
- #ifndef ONLINE_JUDGE
- ///freopen("inp","r",stdout);
- ///freopen("contest.txt","w",stdout);
- #endif
- Do();
- return 0;
- }
Saturday, June 13, 2015
UVa - 386 - Perfect Cubes
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment