Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- int MMC_2(int n1, int n2) {
- int resto, x = n1, y = n2;
- do {
- resto = x % y;
- x = y;
- y = resto;
- } while (resto != 0);
- return ( n1 * n2) / x;
- }
- int MMC_Geral(int *TQ, int N){
- int mmc = TQ[0];
- if (N!=1){
- int i = 0;
- for (i = 1; i < N; i++){
- mmc = MMC_2(mmc, TQ[i]);
- }
- }
- return mmc;
- }
- int acharX(int mmc, int T, int N, int *TQ){
- int i = 0, x = 0;
- for (i = 2; i <= T; i++){
- int Y = MMC_2(mmc, i);
- bool isInvalido = false;
- if (Y == T){
- int j = 0;
- for (j = 0; j < N; j++){
- if (i==TQ[j]){
- isInvalido = true;
- break;
- }
- }
- if (!isInvalido){
- x = i;
- break;
- }
- }
- }
- return x;
- }
- int main(void){
- int N = 0, T = 0; //número de bolas e tempo das N+1 bolas
- scanf("%d %d", &N, &T);
- while((N!=0) && (T!=0)){
- int *TQ = (int*) malloc(N*sizeof(int)); //tempo de quique de cada uma das bolas
- int i = 0;
- for (i = 0; i < N; i++){
- scanf("%d", &TQ[i]);
- }
- int mmc = MMC_Geral(TQ, N);
- int x = acharX(mmc, T, N, TQ);
- if (x==0){
- printf("Impossivel\n");
- }
- else{
- printf("%d\n", x);
- }
- scanf("%d %d", &N, &T);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement