Tuesday, June 18, 2024

# Codeforces Round #392 (Div. 2), problem: (F) Geometrical Progression Solution in C/C++

#include<stdio.h>
#include<stdlib.h>
#define N 10000001
#define SN 3163
typedef long long unsigned llu;
typedef unsigned u;
int F(const void*x,const void*y)
{
if(*(llu*)x>*(llu*)y)return 1;
if(*(llu*)y>*(llu*)x)return-1;
return 0;
}
u D[N],Ga[N],Gi[N];llu *G[N];
int main()
{
u a,b,c,i,j,k,n,x,y,lo,hi,mi;llu e;llu r=0;
for(i=0;++i<SN;)for(k=i*i,j=0;(j+=k)<N;)D[j]=i;
scanf(“%u%u%u”,&n,&x,&y);
if(n<3)
{
r=y-x+1;
if(n==0)r=1;
if(n==2)r=r*(r-1);
printf(“%I64u\n”,r);
return 0;
}
for(a=y+1;a–>x;)
{
for(i=0;++i;)
{
if((b=a/D[a]*(D[a]+i))>y)break;
if((c=b/D[a]*(D[a]+i))>y)break;
if(n==3){++r;continue;}
if((e=c*(llu)(D[a]+i))%D[a]>0||e/D[a]>y)continue;
j=c/(b/D[b]);
lo=0;hi=Gi[b];
while((mi=(lo+hi)>>1)>lo)
{
if((G[b][mi]>>32)>j)hi=mi;
else lo=mi;
}
if(!hi||(G[b][lo]>>32)!=j)k=4;
else k=1+(G[b][lo]&-1u);
if(Gi[a]==Ga[a])
{
if(!Ga[a])G[a]=(llu*)calloc(Ga[a]=1,sizeof(llu));
else G[a]=(llu*)realloc(G[a],(Ga[a]<<=1)*sizeof(llu));
}
G[a][Gi[a]++]=(((llu)(D[a]+i))<<32)|((llu)k);
if(k>=n)++r;
}
if(Gi[a])qsort(G[a],Gi[a],sizeof(llu),F);
}
printf(“%I64u\n”,r<<1);
return 0;
}

## Celebrating Black History Month:...

As February unfolds, so does the annual celebration of...

## The Path to Self-Mastery:...

Embarking on a journey of self-mastery and breaking free...

## Wizards of Waverly Place...

In a spellbinding announcement, Disney has officially revealed that...

## Jim Irsay’s Reported ‘Suspected...

In a shocking turn of events last month, Jim...

Coachella Valley Music and Arts Festival, one of the...

## 2024 Taiwan Election: Pivotal...

As Taiwan gears up for its 2024 presidential election,...

### Celebrating Black History Month: Past, Future

As February unfolds, so does the annual celebration of Black History Month, a time to reflect on the profound contributions, resilience, and rich cultural...

### The Path to Self-Mastery: Lessons from Book ‘The Mountain Is You’

Embarking on a journey of self-mastery and breaking free from self-sabotage is a transformative process that requires dedication and conscious effort. Brianna Wiest's insightful...

### Wizards of Waverly Place Cast Reunites for Enchanting Revival

In a spellbinding announcement, Disney has officially revealed that the beloved fantasy series "Wizards of Waverly Place" is set for a magical comeback, featuring...

### Jim Irsay’s Reported ‘Suspected Overdose’: A Closer Look

In a shocking turn of events last month, Jim Irsay, the owner of the Indianapolis Colts, was reportedly found unresponsive at his home in...

### Coachella 2024: Iconic headliners, unforgettable musical experience!

Coachella Valley Music and Arts Festival, one of the most iconic and eagerly anticipated music festivals globally, has just dropped its highly anticipated lineup...

### 2024 Taiwan Election: Pivotal Moment in Political Landscape

As Taiwan gears up for its 2024 presidential election, the political landscape is buzzing with anticipation and fervor. With the island nation situated at...

### Michael Strahan’s Daughter’s Medulloblastoma Diagnosis

In a recent and heartbreaking revelation, Michael Strahan, former NFL star and television personality, shared the devastating news of his daughter Isabella's diagnosis with...

### Michigan vs. Washington: The 2024 National Championship Clash

In a highly anticipated matchup, the 2024 National Championship will witness a clash of football titans as the Michigan Wolverines square off against the...

### Jason Kelce: Unmasking the Unconventional NFL Icon

In the world of professional football, where conformity often takes center stage, one player stands out as a beacon of individuality, both on and...