948B - Primal Sport - CodeForces Solution


brute force math number theory *1700

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ed "\n"
void ya3ny_m3ttsr3shy() {
    cin.tie(0);
    cin.sync_with_stdio(0);
    cout.tie(0);
    cout.sync_with_stdio(0);
}
bool great(int x,int y){
return x>y;
}
long long power(long long  b ,long long p , long long m){
    if(!p) return 1;
    long long ans = power(b , p/2 , m);
    ans *= ans;
    ans %= m;
    if(p%2) ans *= b , ans %= m;
    return ans%m;
}
bool is_prime(int n){
	if(n==2) return true;
	else if(n==1||n%2==0) return false;
	else{
		int i;
		for(i=3;i*i<=n;i+=2)
           if(n%i==0) return false;}
    return true;
}

int main() {
    ya3ny_m3ttsr3shy();
    int x2,num1,num2,xx2;
    cin>>x2;
    xx2=x2;
    for(ll i=2;i*i<=x2;i++){
        if(x2%i==0) num1=i;
        while(x2%i==0) x2/=i;
    }
    if(x2>1) num1=x2;

    int x1=xx2-num1+1,ans=1e9;
    while(x1<=xx2){
        int num=x1;
        for(ll i=2;i*i<=num;i++){
            if(num%i==0) num2=i;
            while(num%i==0) num/=i;
         }
    if(num>1) num2=num;
    if(x1!=num2)ans=min(ans,x1-num2+1);
    x1++;
    }
    cout<<ans;
    return 0;
}


Comments

Submit
0 Comments
More Questions

1303D - Fill The Bag
1198B - Welfare State
1739B - Array Recovery
1739C - Card Game
1739A - Immobile Knight
1739D - Reset K Edges
817B - Makes And The Product
1452C - Two Brackets
400B - Inna and New Matrix of Candies
870B - Maximum of Maximums of Minimums
1600E - Array Game
1149A - Prefix Sum Primes
277A - Learning Languages
769A - Year of University Entrance
1738A - Glory Addicts
1738C - Even Number Addicts
1064B - Equations of Mathematical Magic
384A - Coder
1738B - Prefix Sum Addicts
1352D - Alice Bob and Candies
1316D - Nash Matrix
1548B - Integers Have Friends
348A - Mafia
315B - Sereja and Array
204A - Little Elephant and Interval
385B - Bear and Strings
114C - Grammar Lessons
1427A - Avoiding Zero
583A - Asphalting Roads
1358B - Maria Breaks the Self-isolation