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 | #include<stdio.h> void q1(){ int i; int num1=0,num3=0; int total=0; for (i=399;i<=8993;i++){ num1=i%10; num3=(i/100)%10; if ((num1+num3)==11){ total+=i; } } printf ( "%d\n" ,total); } void q2(){ int i; int num1=0,num3=0; int total=0; for (i=359;i<=8691;i++){ if (i%7==0 && i%2==0){ total+=i; } } printf ( "%d\n" ,total); } void q3(){ int i; int num1=0,num3=0; int total=0; for (i=95;i<=8505;i++){ if (i%14!=0){ total+=i; } } printf ( "%d\n" ,total); } void q4(){ int i=0,j=0; int total=0; for (i=473;i<=8393;i++){ int count=0; j=i; while (j!=0 && count==0){ if (j%10==3||j%10==6||j%10==8) count++; j=j/10; } if (count!=0) total+=i; } printf ( "%d\n" ,total); } void q5(){ int i; int num1=0,num3=0; int total=0; for (i=486;i<=8817;i++){ num1=i%10; num3=(i/100)%10; if ((num1*num3)==16) total+=i; } printf ( "%d\n" ,total); } int main(){ q1(); q2(); q3(); q4(); q5(); return 0; } |
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 | def q1(): total = 0 ; for i in range ( 399 , 8993 + 1 ): num1 = i % 10 ; num3 = int (i / 100 ) % 10 ; if ((num1 + num3) = = 11 ): total + = i; print (total) def q2(): total = 0 for i in range ( 359 , 8691 + 1 ): if (i % 7 = = 0 and i % 2 = = 0 ): total + = i print (total) def q3(): total = 0 for i in range ( 95 , 8505 + 1 ): if (i % 14 ! = 0 ): total + = i print (total) def q4(): total = 0 for 索引 in range ( 473 , 8393 + 1 ): if str (索引).find( "3" ) ! = - 1 or str (索引).find( "6" ) ! = - 1 or str (索引).find( "8" ) ! = - 1 : total + = 索引 print (total) def q5(): total = 0 ; for i in range ( 486 , 8817 + 1 ): num1 = i % 10 ; num3 = int (i / 100 ) % 10 ; if ((num1 * num3) = = 16 ): total + = i; print (total) q1() q2() q3() q4() q5() |
沒有留言:
張貼留言