What's wrong with a program of Joseph's ring?

Joseph ring
N individuals are numbered sequentially in a circle, starting from the 1st, press 1, 2, 3. Report the number in order, those who report p withdraw from the circle, the rest start from 1, 2, 3, those who report p then quit the circle, and so on. Please output the original serial number of each quitter in exit order.

-sharpinclude<stdio.h>
-sharpinclude<stdlib.h>
struct node{
    int data1;
    int data2;
    struct node *next;
};

int main(void){
    struct node *head, *p, *q, *t;
    int i, N, P, j;
    scanf("%d %d", &N, &P);
    head = NULL;
    for (i = 1; i <= N; iPP){
        p = (struct node*)malloc(sizeof(struct node));
        p->data1 = i;
        p->next = NULL;
        if (head == NULL)
            head = p;
        else
            q->next = p;
        q = p;
    }
    q->next = head;

    t = head;
    while (t != NULL)
    {
        if (t->next->data1 == P){
            printf("%d ", t->next->data1);
            t->next = t->next->next;
            j = 0;
            jPP;

            for (i = 1; i <= N - j; iPP){
                t->next->data2 = i;
                t = t->next;
            }

        }
        t = t->next;
        if(t->next==t){
            printf("%d",t->data1);
            break;
        }
    }

    getchar(); getchar();
    return 0;
}
Aug.07,2021
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bd6dbc-31024.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bd6dbc-31024.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?