2^i ・3^j ・5^k(i,j,kは非負整数)という形で表せる正の整数
100個以前に変数がオーバーフローします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
/* 2^i ・3^j ・5^k(i,j,kは非負整数)という形で表せる正の整数を 小さい順に100個求めるc言語のプログラムを作成してください。 */ #include <stdio.h> #include <math.h> long getNum(int i, int j, int k){ if(i<=0 || j<=0 || k<=0){ return -1; } return (long)(pow(2, i) * pow(3, j) * pow(5, k)); } #define SIZE 100 typedef struct Num_ { long long n; int i; int j; int k; } Num; void cntUpNum(Num *a, int cnt, int i, int j, int k){ a[cnt].n = getNum(i, j, k); a[cnt].i = i; a[cnt].j = j; a[cnt].k = k; } void disp(Num *a, int size){ for(int i=0; i<size; i++){ printf("%lld = 2^%d x 3^%d x 5^%d\n", a[i].n, a[i].i, a[i].j, a[i].k); } } int main(void){ Num a[SIZE]; int i, j, k, cnt = 0; i = j = k = 1; while(1){ cntUpNum(a, cnt++, i , j , k ); cntUpNum(a, cnt++, i+1, j , k ); cntUpNum(a, cnt++, i , j+1, k ); if(SIZE <= cnt){ break; } cntUpNum(a, cnt++, i , j , k+1); cntUpNum(a, cnt++, i+1, j+1, k ); cntUpNum(a, cnt++, i+1, j , k+1); cntUpNum(a, cnt++, i , j+1, k+1); i++; j++; k++; } disp(a, SIZE); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
30 = 2^1 x 3^1 x 5^1 60 = 2^2 x 3^1 x 5^1 90 = 2^1 x 3^2 x 5^1 150 = 2^1 x 3^1 x 5^2 180 = 2^2 x 3^2 x 5^1 300 = 2^2 x 3^1 x 5^2 450 = 2^1 x 3^2 x 5^2 900 = 2^2 x 3^2 x 5^2 1800 = 2^3 x 3^2 x 5^2 2700 = 2^2 x 3^3 x 5^2 4500 = 2^2 x 3^2 x 5^3 5400 = 2^3 x 3^3 x 5^2 9000 = 2^3 x 3^2 x 5^3 13500 = 2^2 x 3^3 x 5^3 27000 = 2^3 x 3^3 x 5^3 54000 = 2^4 x 3^3 x 5^3 81000 = 2^3 x 3^4 x 5^3 135000 = 2^3 x 3^3 x 5^4 162000 = 2^4 x 3^4 x 5^3 270000 = 2^4 x 3^3 x 5^4 405000 = 2^3 x 3^4 x 5^4 810000 = 2^4 x 3^4 x 5^4 1620000 = 2^5 x 3^4 x 5^4 2430000 = 2^4 x 3^5 x 5^4 4050000 = 2^4 x 3^4 x 5^5 4860000 = 2^5 x 3^5 x 5^4 8100000 = 2^5 x 3^4 x 5^5 12150000 = 2^4 x 3^5 x 5^5 24300000 = 2^5 x 3^5 x 5^5 48600000 = 2^6 x 3^5 x 5^5 72900000 = 2^5 x 3^6 x 5^5 121500000 = 2^5 x 3^5 x 5^6 145800000 = 2^6 x 3^6 x 5^5 243000000 = 2^6 x 3^5 x 5^6 364500000 = 2^5 x 3^6 x 5^6 729000000 = 2^6 x 3^6 x 5^6 1458000000 = 2^7 x 3^6 x 5^6 2187000000 = 2^6 x 3^7 x 5^6 3645000000 = 2^6 x 3^6 x 5^7 4374000000 = 2^7 x 3^7 x 5^6 7290000000 = 2^7 x 3^6 x 5^7 10935000000 = 2^6 x 3^7 x 5^7 21870000000 = 2^7 x 3^7 x 5^7 43740000000 = 2^8 x 3^7 x 5^7 65610000000 = 2^7 x 3^8 x 5^7 109350000000 = 2^7 x 3^7 x 5^8 131220000000 = 2^8 x 3^8 x 5^7 218700000000 = 2^8 x 3^7 x 5^8 328050000000 = 2^7 x 3^8 x 5^8 656100000000 = 2^8 x 3^8 x 5^8 1312200000000 = 2^9 x 3^8 x 5^8 1968300000000 = 2^8 x 3^9 x 5^8 3280500000000 = 2^8 x 3^8 x 5^9 3936600000000 = 2^9 x 3^9 x 5^8 6561000000000 = 2^9 x 3^8 x 5^9 9841500000000 = 2^8 x 3^9 x 5^9 19683000000000 = 2^9 x 3^9 x 5^9 39366000000000 = 2^10 x 3^9 x 5^9 59049000000000 = 2^9 x 3^10 x 5^9 98415000000000 = 2^9 x 3^9 x 5^10 118098000000000 = 2^10 x 3^10 x 5^9 196830000000000 = 2^10 x 3^9 x 5^10 295245000000000 = 2^9 x 3^10 x 5^10 590490000000000 = 2^10 x 3^10 x 5^10 1180980000000000 = 2^11 x 3^10 x 5^10 1771470000000000 = 2^10 x 3^11 x 5^10 2952450000000000 = 2^10 x 3^10 x 5^11 3542940000000000 = 2^11 x 3^11 x 5^10 5904900000000000 = 2^11 x 3^10 x 5^11 8857350000000000 = 2^10 x 3^11 x 5^11 17714700000000000 = 2^11 x 3^11 x 5^11 35429400000000000 = 2^12 x 3^11 x 5^11 53144100000000000 = 2^11 x 3^12 x 5^11 88573500000000000 = 2^11 x 3^11 x 5^12 106288200000000000 = 2^12 x 3^12 x 5^11 177147000000000000 = 2^12 x 3^11 x 5^12 265720500000000000 = 2^11 x 3^12 x 5^12 531441000000000000 = 2^12 x 3^12 x 5^12 1062882000000000000 = 2^13 x 3^12 x 5^12 1594323000000000000 = 2^12 x 3^13 x 5^12 2657205000000000000 = 2^12 x 3^12 x 5^13 3188646000000000000 = 2^13 x 3^13 x 5^12 5314410000000000000 = 2^13 x 3^12 x 5^13 7971615000000000000 = 2^12 x 3^13 x 5^13 -9223372036854775808 = 2^13 x 3^13 x 5^13 -9223372036854775808 = 2^14 x 3^13 x 5^13 -9223372036854775808 = 2^13 x 3^14 x 5^13 -9223372036854775808 = 2^13 x 3^13 x 5^14 -9223372036854775808 = 2^14 x 3^14 x 5^13 -9223372036854775808 = 2^14 x 3^13 x 5^14 -9223372036854775808 = 2^13 x 3^14 x 5^14 -9223372036854775808 = 2^14 x 3^14 x 5^14 -9223372036854775808 = 2^15 x 3^14 x 5^14 -9223372036854775808 = 2^14 x 3^15 x 5^14 -9223372036854775808 = 2^14 x 3^14 x 5^15 -9223372036854775808 = 2^15 x 3^15 x 5^14 -9223372036854775808 = 2^15 x 3^14 x 5^15 -9223372036854775808 = 2^14 x 3^15 x 5^15 -9223372036854775808 = 2^15 x 3^15 x 5^15 -9223372036854775808 = 2^16 x 3^15 x 5^15 |