• Loading...

Problem 10: Square Free Function

Points:

Small Case: 5 Answer:139661

Large Case: 15 Answer: 7355940518480

A number is said to be square free if its prime decomposition contains no repeated factors. For example: 6=2*3 is square free, while 12=22 * 3 is not square free.
Find the sum of all N less than or equal to Z for which the value of f(N) is square-free. f(N) is defined as the smallest positive integer M such that AM = 1 (mod N) for all A co-prime to N.

e.g. If N=8
All numbers co-prime to 8 are 1, 3,5 and 7.
12 = 1 = 1 mod 8
32 = 9 = 1 mod 8
52 = 25 = 1 mod 8
72 = 49 = 1 mod 8
So 2 is the smallest such positive integer and since 2 is square-free, 8 will be included in our sum.

Small Case: Z = 1000
Large Case: Z = 10000000

Solution:

In number theory, the Carmichael function f(n) of a positive integer n, is defined as the smallest positive integer m such that am = 1 (mod n) for all a co-prime to n.

Mobius Function is defined by:
mobius(n) = 1 if n is a square-free positive integer with an even number of prime factors.
mobius(n) = −1 if n is a square-free positive integer with an odd number of prime factors.
mobius(n) = 0 if n is not square-free
and (Mobius(f(n)))2,the multiplicative function can be used to determine sqare free carmichael numbers.

Reference:Francesco Pappalardi,Filip Saidak and Igor E. Shparlinski,Square Free values of Carmichael Function, Journal of Number Theory 103(2003) 122–131

Code:


#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include<iostream>
using namespace std;
int A[10000000]={0},F[10000000]={0},isprime[3163];
int getF(int n, int p)
{
     int x,j,e,t;
     if (p==2)x=n/4;
     else x=(n/p)*(p-1);
     for (j=2;j*j<=x;j++)
     {
         if (isprime[j] && x%j==0)
         {
            e=0;
            t=x;
            while (t%j==0)
                  t/=j,e++;
            if (e>1)
               return 0;
         }
     }
     return 1;
}
int main()
{
    int d,n,e,p,k,i,j;
    for (n=2;n<3163;n++)
        isprime[n]=1;

    //Sieve for Eratosthenes for Prime
    //Storing the smallest prime which divides n.
    //If A[n]=0 it means it is prime number.
    for(d=2;d<3163;d++)
    {
        if(isprime[d])
        {
            for (n=d*d;n<3163;n+=d)
            {
                isprime[n]=0;
                A[n]=d;
            }
            for (;n<=10000000;n+=d)
                A[n]=d;
        }
    }

    //Applying the formula
    //F[n]=Mu^2(Lambda(n)) is Multiplicative
    F[1]=1;F[2]=1;F[3]=1;F[4]=1;
    for(n=5;n<=10000000;n++)
    {
        if (A[n]==0)
        {
           F[n]=getF(n,n);
        }
        else
        {
           p=A[n],k=n/p,e=p;
           while (k%p==0)
                 k/=p,e*=p;
           if (k==1) 
            F[n]=getF(n,p);
           else F[n]=F[k]*F[e];
        }
    }
    long long s=0;
    for (n=1;n<=10000000;n++)
        if(F[n])
                s+=n;
    cout<<s<<endl;
    return 0;
}

Submit your solution

You need to be logged in to submit a solution.

discussions


rng_58N = 1
Q:is N = 1 counted?
A:Yes

post a question

Loading...

Problem 1
Problem 2
Problem 3
Problem 4
Problem 5 (bonus) Expired
Problem 1
Problem 2
Problem 3
Problem 4 (bonus) Expired
Top Scorers
rng_58 235
Anton_Lunyov 225
tourist 190
Silence 180
cedricl2 175
cgy4ever 175
DrKorbin 165
Koen 155
bbbasic 150
lunae_2 150
Submissions
Problem 1
10 pt
not submitted
98
submissions

19
correct (19 %)



25 pt
not submitted
2
submissions

1
correct (50 %)


Problem 2
5 pt
not submitted
95
submissions

38
correct (40 %)



10 pt
not submitted
19
submissions

15
correct (78 %)


Problem 3
5 pt
not submitted
153
submissions

117
correct (76 %)



15 pt
not submitted
44
submissions

25
correct (56 %)


Problem 4
10 pt
not submitted
152
submissions

54
correct (35 %)



15 pt
not submitted
23
submissions

10
correct (43 %)


Problem 5
10 pt
not submitted
36
submissions

28
correct (77 %)



20 pt
not submitted
6
submissions

2
correct (33 %)


Problem 6
5 pt
not submitted
41
submissions

29
correct (70 %)



10 pt
not submitted
15
submissions

14
correct (93 %)


Problem 7
5 pt
not submitted
38
submissions

17
correct (44 %)



10 pt
not submitted
16
submissions

15
correct (93 %)


Problem 8
5 pt
not submitted
127
submissions

104
correct (81 %)



15 pt
not submitted
47
submissions

34
correct (72 %)


Problem 9
5 pt
not submitted
86
submissions

35
correct (40 %)



15 pt
not submitted
16
submissions

15
correct (93 %)


Problem 10
5 pt
not submitted
45
submissions

23
correct (51 %)



15 pt
not submitted
15
submissions

14
correct (93 %)


Problem 11
5 pt
not submitted
81
submissions

27
correct (33 %)



15 pt
not submitted
8
submissions

3
correct (37 %)


Problem 12
5 pt
not submitted
104
submissions

88
correct (84 %)



10 pt
not submitted
31
submissions

21
correct (67 %)