21 Lanqiao Cup D question C language solution

    First, in general, what I think of is to find the factors and iterate through them to get the answer, but after running, this takes a very long time. So we do it in a decomposed way.

#include<stdio.h>
int main()
{
	int n=2021041820210418;
	int i,j=0,k,u,m,o;
	int a[1000];
	int s1,s2,s3;
	int count=0;
	for(i=1;i*i*i<=n;i++){
		if(n%i==0){
			for(k=1;i*k*k<=n;k++){
				if(n/i%k==0){
					m=n/i/k;
					if(i==k&&k==m){
						count+=1;
				    }
					else if(i==k||i==m||k==m){
						count+=3;
					}
					else 
					    count+=6;
				}
			}
		}
	}
	printf("%d",count);
	return 0;
}

After decomposition it ran smoothly and the timing was normal.

おすすめ

転載: blog.csdn.net/kgb2333/article/details/134529649