ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1024. Permutations

WA #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
Posted by Khujamurod97 10 Dec 2017 15:06
I tried to repair your code
[code deleted]

Edited by moderator 04.12.2019 20:38