zoukankan      html  css  js  c++  java
  • (Problem 3)Largest prime factor

    The prime factors of 13195 are 5, 7, 13 and 29.

    What is the largest prime factor of the number 600851475143 ?

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<ctype.h>
    #include<stdlib.h>
    #include<stdbool.h>
    
    #define N 600851475143
    
    bool prim(int n)
    {
    	int i;
    	for(i=2; i*i<=n; i++)
    	{
    		if(n%i==0)
    			return false;
    	}
    	return true;
    }
    
    int main()
    {
    	long long s=sqrt(N);
    	while(s--)
    	{
    		if(s%2!=0 && prim(s) && (N%s==0))
    		{
    			
    			printf("%lld\n",s);
    			break;
    		}
    	}
    	return 0;
    }
    

    Answer:
    6857

  • 相关阅读:
    CSPS模拟 57
    CSPS模拟 56
    CSPS Oct目标
    CSPS模拟 55
    CSPS模拟 54
    CSPS模拟 53
    和manacher有关的乱写
    CSPS模拟 52
    CSPS模拟 51
    Git和代码规范
  • 原文地址:https://www.cnblogs.com/cpoint/p/3367370.html
Copyright © 2011-2022 走看看