1 solutions

  • 0
    @ 2025-11-5 19:50:49

    C :

    #include<stdio.h>
    #include<ctype.h>
    
    int main() 
    {
            char str[128];
            int N,r,i,j;
            for(scanf("%d",&N);N--;) 
    		{
                    scanf("%s",str);
                    for(i=r=0;str[i];i++) 
    					if (isdigit(str[i]))
    						r=r*10+str[i]-'0';
                    if (!r) 
    					j=0; 
    				else if (r==1) 
    					j=1; 
    				else 
    				{
                            for(i=2;(long)i*i<=r;i++) 
    							if (r%i==0) 
    							{
                                    j=i;
                                    while(r%i==0) 
    									r/=i;
                            }
                            if (r>1) j=r;
                    }
                    printf("%d\n",j);
            }
            return 0;
    }
    

    C++ :

    #include<stdio.h>
    #include<ctype.h>
    
    int main() {
    	char str[128];
    	int N,r,i,j;
    	for(scanf("%d",&N);N--;) {
    		scanf("%s",str);
    		for(i=r=0;str[i];i++) if (isdigit(str[i])) r=r*10+str[i]-'0';
    		if (!r) j=0; else if (r==1) j=1; else {
    			for(i=2;(long long)i*i<=r;i++) if (r%i==0) {
    				j=i;
    				while(r%i==0) r/=i;
    			}
    			if (r>1) j=r;
    		}
    		printf("%d\n",j);
    	}
    	return 0;
    }
    
    
    • 1

    Information

    ID
    19738
    Time
    1000ms
    Memory
    32MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By