Cancer is overwhelmingly a result of environmental factors and not largely down to bad luck, a study suggests.