|
|
back to boardWA #12 I think it's all fine, but... Please, help Posted by _Link 4 Feb 2015 16:02 This works correct even with 1000 numbers. (What else compilator wants? )) #include <stdio.h> int nod(int a, int b){ while (a != 0 && b != 0){ if (a > b) a = a % b; else b = b % a; } return a+b; } int main(){ int size; int result = 1; scanf_s("%i", &size); int arr[1001]; bool mask[1001]; for (int i = 0; i < size; ++i) scanf_s("%i", &arr[i]); for (int i = 0; i < size; ++i){ int k = 1, temp = arr[i]; while (temp != i + 1){ temp = arr[temp - 1]; ++k; } if (mask[k] != false){ mask[k] = false; result =result/nod(result,k) * k; } } printf("%i", result); } Re: WA #12 I think it's all fine, but... Please, help I tried to repair your code [code deleted] Edited by moderator 04.12.2019 20:38 |
|
|