Tags » Sieve

The Sieve Initiative

I have deployed the sieve.

Yes, this is as ominous as it sounds. Shudder, if you please.

In an attempt not to be overtly wordy in my first Cozy Mystery, I have soldered a fine-meshed strainer to my head. 42 more words

Author

Light OJ 1028 - Trailing Zeroes (I) [solved]

/******************************************
          Mobarak Hosen Shakil
        ICE, Islamic University
     ID: mhiceiuk(all), 29698(LOJ)
   E-mail: mhiceiuk @ (Gmail/Yahoo/FB)
 Blog: https://iuconvergent.wordpress.com
*******************************************/

#include<bits/stdc++.h>
#define sroot 1000007

using namespace std;
vector <int> primes;


int sieve()
{
    bool a;
    memset(a, 0, sizeof(a));

    for(int i = 2; i <= sroot; i++) {
        if(a[i] == 0) {
            for (int j = i + i; j <= sroot; j = j + i) {
                a[j] = 1;
            }

        }

    }
    primes.push_back(2);
    for (int i = 3; i <= sroot; i+=2) {
        if(a[i] == 0) {
            primes.push_back(i);
        }

    }

}

int main()
{
    sieve();

    int t;
    long long x, sum, k, temp, n;
    ///cout<<primes.size()<<endl;

    scanf("%d", &t);

    for (int cases = 1; cases <= t; cases++) {
        scanf("%lld", &x);
        sum = 1;
        n = sqrt(x);

        for(int i = 0; i <= primes.size() - 1 and primes[i] <= n ; i++) {

            k = 0;
            if(x < primes[i]) {
                break;
            }

            while(x % primes[i] == 0) {

                x = x / primes[i];
                k++;
            }

            sum = sum * (k + 1);

        }

        if(x > 1) sum *= 2;
        ///cout << x << endl;
        sum = sum - 1;

        printf("Case %d: %lld\n",cases, sum);

    }

}
Light OJ

UVa 10791 - Minimum Sum LCM [solved]

/******************************************
          Mobarak Hosen Shakil
        ICE, Islamic University
     ID: mhiceiuk(all), 29698(LOJ)
   E-mail: mhiceiuk @ (Gmail/Yahoo/FB)
 Blog: https://iuconvergent.wordpress.com
*******************************************/

#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define M 100000000
int marked;
#define on(x) (marked & (1<<((x%64)/2)))
#define mark(x) marked |= (1<<((x%64)/2))

typedef long long LL;

vector<int> p;

bool isPrime(int num) {
    return num > 1 && (num == 2 || ((num & 1) && !on(num)));
}

void sieve(int n)
{
    p.pb(2);
    for (int i = 3; i * i < n; i += 2) {
        if (!on(i)) {
            p.pb(i);
            for (int j = i * i; j <= n; j += i + i) {
                mark(j);
            }
        }
    }

    for(int i=3; i<n; i+=2)
        if(isPrime(i))p.pb(i);
}


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, cn=0;
    sieve(46350);
    while(cin>>n && n!=0)
    {

        LL pr, sum=0;
       //// cout<<p.size()<<endl;
        int fact=0;
        if(n==1){
            sum=2;
        }
        else
        {
            for(int i=0; i<p.size() && n!=1; i++)
            {
                if(n%p[i]==0)
                {
                    pr=1;
                    while(n%p[i]==0 && n!=1)
                    {
                        n/=p[i];
                        pr*=p[i];
                    }
                    sum+=pr;
                    fact++;
                }
            }
            if(n>1) {
                fact++;
                sum+=n;
            }
            if(fact<2)sum+=1;
        }
        cout<<"Case "<<++cn<<": "<<sum<<endl;
    }
    return 0;
}
UVa Problems

Sunday

Garlic

The second thing that Loved One said to me this morning was “you still smell of garlic”. I was starting to get a little paranoid about the smell of garlic. 323 more words

Random Thoughts

Enter: the Censor


Listen to yourself breathe.
Look outward with glossy stare.
Become the hunted.
Become what you seek.
Then never look into the mirror.

Press eyes into the sieve. 26 more words

Poetry

Sieve

Do not pour your time and emotion into
Petty disagreements

For these are merely

False vessels;

Sieves

Which drain the

Giver

And create nothing but

Illusions.