Codeforces Round #473 (Div. 2), problem: (D) Mahmoud and Ehab and another array construction task Solution In C/C++

#include<stdio.h>
int vi[10000001]={0};
int main(void)
{
int n, a, now = 2;
int ans;
scanf(“%d”, &n);
int flag = 0;
int i,j,k;
for (i = 1; i <= n; i++)
{
scanf(“%d”, &a);
ans = now;
if (!flag&&a>ans)
ans = a;
while (vi[ans])
ans++;
printf(“%d “, ans);
if (ans>a)
flag = 1;
for (j = now; j*j <= ans; j++)
{
if (ans%j)
continue;
while (ans%j == 0)
ans /= j;
if (!vi[j])
for (k = j; k<10000001; k += j)
vi[k] = 1;
}
if (ans != 1)
for ( j = ans; j<10000001; j += ans)
vi[j] = 1;
while (vi[now])
now++;
}
return 0;
}

Advertisement

spot_img

Is the Epicka Universal...

Long-Term Travel Endurance: Is the Epicka Adapter Worth $20? In...

Top 7 Travel Packing...

Mastering the Carry-On: Pro Packing and Power Management for...

Epicka Travel Adapter European...

The Grand European Tour: Navigating Continental Type C, E,...

Can You Use the...

Cross-Pacific Power: Using the Epicka Adapter in Japan and...

Does the Epicka Travel...

Mastering British Standard BS 1363: Surviving UK and Irish...

Epicka Universal Travel Adapter...

Apple Ecosystem Travelers: Proprietary Duckheads vs. Universal Power For dedicated...

Is the Epicka Universal Travel Adapter Worth $20? Long-Term Durability Review

Long-Term Travel Endurance: Is the Epicka Adapter Worth $20? In the world of travel gear, budget accessories priced under $25 often carry an unfortunate stigma....

Top 7 Travel Packing and Power Management Tips for International Trips

Mastering the Carry-On: Pro Packing and Power Management for Globetrotters In modern international travel, keeping your personal electronic devices charged and operational is no longer...

Epicka Travel Adapter European Travel Guide: France, Italy, Germany, and Spain

The Grand European Tour: Navigating Continental Type C, E, and F Outlets A grand tour across continental Europe is a bucket-list dream for travelers worldwide....

Can You Use the Epicka Travel Adapter in Japan and North America (Type A & B)?

Cross-Pacific Power: Using the Epicka Adapter in Japan and North America For travelers planning vacations or corporate business trips across the Pacific—traveling between the United...

Does the Epicka Travel Adapter Work in the UK and Ireland (Type G Sockets)?

Mastering British Standard BS 1363: Surviving UK and Irish Wall Sockets For North American and international travelers visiting London, Edinburgh, Dublin, or Belfast, their first...

Epicka Universal Travel Adapter vs Apple World Travel Adapter Kit

Apple Ecosystem Travelers: Proprietary Duckheads vs. Universal Power For dedicated Apple enthusiasts who travel with an iPhone, Apple Watch, iPad, and MacBook, Apple's official accessory...

Is the Epicka Travel Adapter Safe for CPAP Machines While Traveling Abroad?

Traveling with Sleep Apnea: Can You Power Your CPAP Machine with Epicka? For millions of individuals diagnosed with obstructive sleep apnea (OSA), a Continuous Positive...

Epicka Universal Travel Adapter USB Charging Speeds: Real-World Benchmarks

Benchmarking Real-World Power: How Fast Does the Epicka Adapter Charge? When shopping for multi-port travel chargers, manufacturer marketing claims often highlight impressive-sounding numbers like "5.6...

Can You Charge a MacBook or Laptop with the Epicka Travel Adapter USB-C Port?

Powering Your Mobile Office Abroad: Can Epicka Handle Modern Laptops? For business travelers, digital nomads, and vacationers who need to stay connected, a laptop is...