第十四届蓝桥杯三月真题刷题训练——第 15 天 （3.18）

ck 2023-03-18 10:26:31

``````#include <iostream>
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <unordered_map>
#include <queue>
#include <algorithm>
#define x first
#define y second
#define pb emplace_back
#define fu(i,a,b) for(int i=a;i<=b; ++ i)
#define fd(i,a,b) for(int i=a;i>=b;    -- i)
#define endl '\n'
#define ms(x,y) memset(x,y,sizeof x)
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;

typedef long long LL;
typedef vector<vector<LL>> VVL;
typedef vector<vector<int>> VVI;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef pair<PII,int> PIII;
typedef pair<double,double> PDD;
typedef pair<double,int> PDI;
typedef pair<char,int> PCI;
typedef pair<string,int> PSI;
typedef pair<int,string> PIS;
typedef pair<int,char> PIC;
typedef pair<LL,LL> PLL;
typedef __int128 i128;
typedef unsigned long long ULL;
const int N = 100000+ 10   ,INF = 0x3f3f3f3f ;
const int mod = 1e8 ;
const double eps = 1e-8;

LL f[N];
LL n =  202202011200;

inline void solve()
{
LL ans =0;
f[1] = 1 ,f[2] =1 ;
fu(i,3,100)
{
f[i] = (f[i-1] + f[i-2]) % 10 ;
}

ans += n / 60 * 8 ;n %= 60;

fu(i,3,n)
if(f[i] % 10 == 7 ) ans ++ ;

cout << ans <<endl;

}
signed main()
{
//  freopen("1.txt","w",stdout);
ios

//    cout << fixed<<setprecision(3);
int t=1;
//    cin>>t;
int now = 1;
while(t -- )
{
//      cout<<"Case ";
//      cout<<"Scenario #";
//      cout<< now ++ <<": ";
//      cout<< now ++ <<": \n";
solve();
}

return 0;
}``````

``````#include <iostream>
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <unordered_map>
#include <queue>
#include <algorithm>
#define x first
#define y second
#define pb emplace_back
#define fu(i,a,b) for(int i=a;i<=b; ++ i)
#define fd(i,a,b) for(int i=a;i>=b;	-- i)
#define endl '\n'
#define ms(x,y) memset(x,y,sizeof x)
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<vector<LL>> VVL;
typedef vector<vector<int>> VVI;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef pair<PII,int> PIII;
typedef pair<double,double> PDD;
typedef pair<double,int> PDI;
typedef pair<char,int> PCI;
typedef pair<string,int> PSI;
typedef pair<int,string> PIS;
typedef pair<int,char> PIC;
typedef pair<LL,LL> PLL;
typedef __int128 i128;
typedef unsigned long long ULL;
const int N = 1e8+ 10   ,INF = 0x3f3f3f3f ;
const int mod = 1e8 ;
const double eps = 1e-8;

bool check(LL x)
{
for(LL i =2 ;i <= x / i + 1  ;i ++ )
if(x % i == 0 ) return 0;
return 1;

}

inline void solve()
{
cout << 342693<<endl;return;
LL ans =0;
LL n;
while(cin >> n )
{
ans += check(n);
}
cout << ans <<endl;

}
signed main()
{

// freopen("1.txt","r",stdin);
ios

//	cout << fixed<<setprecision(3);
int t=1;
//    cin>>t;
int now = 1;
while(t -- )
{
//      cout<<"Case ";
//      cout<<"Scenario #";
//      cout<< now ++ <<": ";
//      cout<< now ++ <<": \n";
solve();
}

return 0;
}
``````

``````#include <iostream>
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <unordered_map>
#include <queue>
#include <algorithm>
#define x first
#define y second
#define pb emplace_back
#define fu(i,a,b) for(int i=a;i<=b; ++ i)
#define fd(i,a,b) for(int i=a;i>=b;	-- i)
#define endl '\n'
#define ms(x,y) memset(x,y,sizeof x)
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<vector<LL>> VVL;
typedef vector<vector<int>> VVI;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef pair<PII,int> PIII;
typedef pair<double,double> PDD;
typedef pair<double,int> PDI;
typedef pair<char,int> PCI;
typedef pair<string,int> PSI;
typedef pair<int,string> PIS;
typedef pair<int,char> PIC;
typedef pair<LL,LL> PLL;
typedef __int128 i128;
typedef unsigned long long ULL;
const int N = 1e8+ 10   ,INF = 0x3f3f3f3f ;
const int mod = 1e8 ;
const double eps = 1e-8;

inline void solve()
{
LL n;cin >> n;
LL ans;
fu(i,2,n/i)
{
if(n % i == 0 )
{
ans ++;
while(n % i == 0) n/=i;
}

}
if(n > 1 ) ans ++ ;

cout << ans << endl;

}
signed main()
{
//  freopen("1.txt","r",stdin);
ios

//	cout << fixed<<setprecision(3);
int t=1;
//    cin>>t;
int now = 1;
while(t -- )
{
//      cout<<"Case ";
//      cout<<"Scenario #";
//      cout<< now ++ <<": ";
//      cout<< now ++ <<": \n";
solve();
}

return 0;
}
``````

``````#include <iostream>
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <unordered_map>
#include <queue>
#include <algorithm>
#define x first
#define y second
#define pb emplace_back
#define fu(i,a,b) for(int i=a;i<=b; ++ i)
#define fd(i,a,b) for(int i=a;i>=b;	-- i)
#define endl '\n'
#define ms(x,y) memset(x,y,sizeof x)
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<vector<LL>> VVL;
typedef vector<vector<int>> VVI;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef pair<PII,int> PIII;
typedef pair<double,double> PDD;
typedef pair<double,int> PDI;
typedef pair<char,int> PCI;
typedef pair<string,int> PSI;
typedef pair<int,string> PIS;
typedef pair<int,char> PIC;
typedef pair<LL,LL> PLL;
typedef __int128 i128;
typedef unsigned long long ULL;
const int N = 1e5+ 10   ,INF = 0x3f3f3f3f ;
const int mod = 1e8 ;
const double eps = 1e-8;

int n,f[N][31],Log2[N],a[N];

void init()
{
fu(i,2,n) Log2[i] =Log2[i>>1] + 1 ;
fu(i,1,n) f[i][0] = a[i];

fu(i,1,30)
for(int j=1 ;j + (1<<i) - 1 <= n; j ++ )
f[j][i] = __gcd(f[j][i-1],f[j+(1<<(i-1))][i-1]);

}

int query(int l,int r)
{
int len = Log2[r-l+1];

return __gcd(f[l][len],f[r-(1<<len)+1][len]);
// [l,l + 2^len] [r - 2^len + 1,r] // 可能有重合，但不影响答案
}

inline void solve()
{
cin >> n;
int f =0 ;
fu(i,1,n)
{
cin >> a[i];if(a[i]== 1) f ++ ;
}

if(f)
{
cout << n - f << endl;return;
}
init();

if(query(1,n) != 1 )
{
cout << -1 <<endl;return;
}

int ans = INF;

fu(i,1,n) // 枚举先把第i个数变成1
{
int l= i + 1 ,r = n;
while(l < r )
{
int mid = l + r >> 1;
if(query(i,mid) == 1 ) r = mid;
else l = mid + 1;
}
if(query(i,r) == 1 ) ans = min(ans,r-i);
}
cout << n - 1 + ans << endl;

}
signed main()
{
//  freopen("1.txt","r",stdin);
ios

//	cout << fixed<<setprecision(3);
int t=1;
//    cin>>t;
int now = 1;
while(t -- )
{
//      cout<<"Case ";
//      cout<<"Scenario #";
//      cout<< now ++ <<": ";
//      cout<< now ++ <<": \n";
solve();
}

return 0;
}
``````

...全文
10 回复 打赏 收藏 举报

3.5w+

2023-03-18 11:53

2023-03-18 10:53

2023-03-18 10:47

2023-03-18 10:26

刷题！