cf1646 属于是写啥哇啥
C 大佬的代码真的好优美
#include <bits/stdc++.h>
using namespace std;
const int INF = 100;
int main(){
vector<long long> fact;
for (int i = 3; i <= 14; i++){
long long P = 1;
for (int j = 1; j <= i; j++){
P *= j;
}
fact.push_back(P);
}
int t;
cin >> t;
for (int i = 0; i < t; i++){
long long n;
cin >> n;
int ans = INF;
for (int j = 0; j < (1 << 12); j++){
long long n2 = n;
for (int k = 0; k < 12; k++){
if ((j >> k & 1) == 1){
n2 -= fact[k];
}
}
if (n2 >= 0){
ans = min(ans, __builtin_popcount(j) + __builtin_popcountll(n2));
}
}
cout << ans << endl;
}
}
#include <stdio.h>
#define N 15
#define INF 0x3f3f3f3f
int min(int a, int b) { return a < b ? a : b; }
long long ff[N + 1];
void init() {
int n;
ff[0] = 1;
for (n = 1; n <= N; n++) {
ff[n] = ff[n - 1] * n;
if (ff[n] > 1000000000000)
break;
}
}
int count(long long n) {
return n == 0 ? 0 : count(n & n - 1) + 1;
}
int main() {
int t;
init();
scanf("%d", &t);
while (t--) {
long long n, n_;
int b, i, ans;
scanf("%lld", &n);
ans = INF;
for (b = 0; b < 1 << N; b += 4) {
n_ = 0;
for (i = 0; i < N; i++)
if ((b & 1 << i) != 0)
n_ += ff[i];
if (n_ <= n)
ans = min(ans, count(b) + count(n - n_));
}
printf("%d\n", ans);
}
return 0;
}
#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int cal(int x)
{
int rtn=0;
while(x)
rtn+=x&1,x>>=1;
return rtn;
}
int fac[20];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
fac[1]=1;
for(int i=2;i<=15;i++)
fac[i]=fac[i-1]*i;
while(T--)
{
int x;
cin >> x;
int ans=1e9;
for(int i=0;i<65536;i++)
{
int s=0,cnt=0;
for(int j=0;j<15;j++)
{
if(i&(1<<j))
{
s+=fac[j+1];
++cnt;
}
}
if(s<=x)
{
ans=min(ans,cnt+cal(x-s));
}
}
cout << ans << "\n";
}
return 0;
}
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int TT;
cin >> TT;
while (TT--) {
long long N;
cin >> N;
vector<long long> fact({1});
while (fact.back() <= N) {
fact.push_back(fact.back() * int(fact.size()));
}
fact.pop_back();
int size = int(fact.size());
int ans = 100;
for (int i = 0; i < (1 << size); ++i) {
long long sum = 0;
for (int j = 0; j < size; ++j) {
if ((i >> j) & 1) {
sum += fact[j];
}
}
ans = min(ans, __builtin_popcount(i) + __builtin_popcountll(N - sum));
}
cout << ans << '\n';
}
}
B
我以为是只需要判断a[n-1]和a[0]+a[1]的大小就行了 物大地博🤯
nmd还需要加很多 动态加a[2],a[3],动态减去a[n-2] a[n-3]
A
我人麻了 rnm亏我加ll
s/(n*n)和s/pow(n,2)不一样
pow是double的数据,可能会有精度丢失
E
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, m;
cin >> n >> m;
vector<int> mx(n + 1, 1);
vector<bool> ok(n + 1, true);
for (int i = 2; i * i <= n; i++){
long long P = i;
while (true){
P *= i;
if (P > n){
break;
}
ok[P] = false;
mx[i]++;
}
}
vector<bool> used(m * 20 + 1, false);
vector<int> cnt(21, 0);
int c = 0;
for (int i = 1; i <= 20; i++){
for (int j = 1; j <= m; j++){
if (!used[i * j]){
used[i * j] = true;
c++;
}
}
cnt[i] = c;
}
long long ans = 1;
for (int i = 2; i <= n; i++){
if (ok[i]){
ans += cnt[mx[i]];
}
}
cout << ans << endl;
}
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i)
#define DOR(i,s,t) for(int i=(s),_t=(t); i>=_t; --i)
typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
#define fi first
#define se second
const int Mod=1e9+7;
const int N=1e6+50;
ll f[21];
ll g[20*N];
int vis[N];
int main() {
int n,m;
scanf("%d%d",&n,&m);
FOR(i,1,20) {
f[i]=f[i-1];
FOR(j,1,m) if(!g[i*j]) g[i*j]=1,++f[i];
}
ll res=1;
FOR(i,2,n) {
if(vis[i]) continue;
int c=1,j=i;
while(1ll*j*i<=n) {
j*=i;
++c;
vis[j]=1;
}
res+=f[c];
}
printf("%lld\n",res);
return 0;
}