Project Euler #241: Perfection Quotients

Sort by

recency

|

38 Discussions

|

  • + 0 comments

    for(int i=0; i<10^18; i++) if(a % 47 == 0) int f = 45; else int g = 0;

  • + 0 comments

    can i do it in vba? I dont see a option but it's the easier to me to use it

  • + 0 comments
    import math
    def divsum(n):
        result=0
        for i in range(2,(int)(math.sqrt(n))+1):
            if(n%i==0):
                if(i==n/i):
                    result=result+i
                else:
                    result=result+(i+n//i)
        return (result+n+1)
    number=int(input())
    value=0
    for i in range(1,number+1):
        if((divsum(i)/i)-(divsum(i)//i)==float(1/2)):
            value=value+i
    print(value)
    

    please help me to optimize my code ,it didn't execute within the time limits for many test cases.

    lue) `

  • + 0 comments

    Can someone tell why this code isn't working for range<10^18?? I know the max range in java for long is 10^19, but at least it should give correct for those test cases.!

    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        public static int perfect(long n){
            long sum=n+1;
            for(long i=2;i<=Math.sqrt(n);i++){
                if(n%i==0)
                sum+=i;
            }
            if(sum==n)
            return 1;
            else
            return 0;
        }
        public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            Scanner sc=new Scanner(System.in);
            long n=sc.nextLong();
            long sum=0;
            for(long i=1;i<=n;i++){
                if(perfect(i)==1){
                    long sigma=2*n;
                    double p=sigma/n;
                    long k=(long)p;
                    if(k-p==0.5)
                    sum+=i;
                }
            }
            System.out.println(sum);
        }
    }
    
  • + 0 comments

    This is my code. I'm getting run-time error. I think I have written correct algorithm. Can anyone tell me where I am wrong...

    include

    include

    using namespace std;

    typedef unsigned long long ll;

    bool pq(ll); ll sigma(ll);

    int main() { ll sum=0,n,i; bool truth; cin>>n; for(i=0;i