Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* The four adjacent digits in the 1000-digit number
- * 7316717653133062491922511967442657474235534919493496983520312774506
- * 3262395783180169848018694788518438586156078911294949545950173795833
- * 1952853208805511125406987471585238630507156932909632952274430435576
- * 6896648950445244523161731856403098711121722383113622298934233803081
- * 3533627661428280644448664523874930358907296290491560440772390713810
- * 5158593079608667017242712188399879790879227492190169972088809377665
- * 7273330010533678812202354218097512545405947522435258490771167055601
- * 3604839586446706324415722155397536978179778461740649551492908625693
- * 2197846862248283972241375657056057490261407972968652414535100474821
- * 6637048440319989000889524345065854122758866688116427171479924442928
- * 2308634656748139191231628245861786645835912456652947654568284891288
- * 3142607690042242190226710556263211111093705442175069416589604080719
- * 8403850962455444362981230987879927244284909188845801561660979191338
- * 7549920052406368991256071760605886116467109405077541002256983155200
- * 05593572972571636269561882670428252483600823257530420752963450
- * that have the greatest product are: 9 × 9 × 8 × 9 = 5832. Find the
- * thirteen adjacent digits in the 1000-digit number that have the
- * greatest product. What is the value of this product?
- */
- #include <stdio.h>
- int main()
- {
- char source_sequence[] = "7316717653133062491922511967442657474235534919493\
- 49698352031277450632623957831801698480186947885184385861560789112949495459501737\
- 95833195285320880551112540698747158523863050715693290963295227443043557668966489\
- 50445244523161731856403098711121722383113622298934233803081353362766142828064444\
- 86645238749303589072962904915604407723907138105158593079608667017242712188399879\
- 79087922749219016997208880937766572733300105336788122023542180975125454059475224\
- 35258490771167055601360483958644670632441572215539753697817977846174064955149290\
- 86256932197846862248283972241375657056057490261407972968652414535100474821663704\
- 84403199890008895243450658541227588666881164271714799244429282308634656748139191\
- 23162824586178664583591245665294765456828489128831426076900422421902267105562632\
- 11111093705442175069416589604080719840385096245544436298123098787992724428490918\
- 88458015616609791913387549920052406368991256071760605886116467109405077541002256\
- 98315520005593572972571636269561882670428252483600823257530420752963450";
- char checked_sequence[14];
- long int accumulator;
- long int max_value = 1;
- short int i;
- char j;
- for(i = 0; i < 987; i++)
- {
- accumulator = 1;
- for(j = 0; j < 13; j++)
- {
- switch (source_sequence[i + j])
- {
- case '0': accumulator *= 0; break;
- case '1': accumulator *= 1; break;
- case '2': accumulator *= 2; break;
- case '3': accumulator *= 3; break;
- case '4': accumulator *= 4; break;
- case '5': accumulator *= 5; break;
- case '6': accumulator *= 6; break;
- case '7': accumulator *= 7; break;
- case '8': accumulator *= 8; break;
- case '9': accumulator *= 9; break;
- }
- }
- if(accumulator > max_value)
- {
- max_value = accumulator;
- for(j = 0; j < 13; j++)
- checked_sequence[j] = source_sequence[i + j];
- }
- }
- printf("The sequence is %s, the product is %ld\n",
- checked_sequence, max_value);
- return(0);
- }
- /* The sequence is 5576689664895, the product is 23514624000 */
- /* real 0m0,003s
- * user 0m0,000s
- * sys 0m0,002s */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement