标签:name turn printf break vector problem fine nod bsp
http://codeforces.com/gym/226123/problem/L
题解:手摸几组数据,发现一个规律:将n 质因数分解,答案就是 每个质因数/2+1后再乘起来。
然后考虑2的情况:
2 | 8 | 16 | 32 | 64 |
1 | 5 | 9 | 15 | 25 |
#define _CRT_SECURE_NO_WARNINGS #include<cmath> #include<iostream> #include<stdio.h> #include<algorithm> #include<cstring> using namespace std; #define rep(i,t,n) for(int i =(t);i<=(n);++i) #define per(i,n,t) for(int i =(n);i>=(t);--i) #define mmm(a,b) memset(a,b,sizeof(a)) #define eps 1e-6 const int maxn = 1e6+5; int a[maxn]; int isp[maxn]; int cnt[maxn]; typedef long long ll; struct node { }; ll n; ll ans = n / 2 + 1; void run(int n) { ans = n / 2 + 1; for (ll i = 1; i*i <= n; i++)if (n%i == 0) { ll x = (i / 2 + 1)*(((n / i) / 2) + 1); ans = min(ans, x); } } int main() { rep(i, 1, maxn)isp[i] = 1; rep(i, 2, maxn)if (isp[i]) { for (int j = 2 * i; j <= maxn; j += i)isp[j] = 0; } while (cin >> n) { ll ans = 1; int cnt=0; while (n % 2 == 0)n /= 2, cnt++; while (cnt >= 3) { if (cnt == 4) { cnt -= 4; ans *= 9; } else { cnt -= 3; ans *= 5; } } if (cnt == 1) { ans *= 2; } if (cnt == 2)ans *= 3; rep(i, 3, maxn-1) if(isp[i]){ while (n%i == 0)ans *= (i/2 + 1),n/=i; if (n == 1)break; } ans *= (n/2+1); cout << ans; } } /* qwer qwre 1000000000 */
dfs:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<map> #include<queue> using namespace std; typedef long long ll; map<int,int>sp; void solve(int t){ if(sp[t])return ; sp[t]=t/2+1; for(int i=2;i*i<=t;i++){ if(t%i==0){ solve(t/i); solve(i); sp[t]=min(sp[t],sp[t/i]*(i/2+1)); sp[t]=min(sp[t],sp[i]*(t/i/2+1)); } } } int main(){ int n,i,j; scanf("%d",&n); solve(n); printf("%d\n",sp[n]); return 0; }
【瞎搞题】gym226123 L. For the Honest Election
标签:name turn printf break vector problem fine nod bsp
原文地址:https://www.cnblogs.com/SuuT/p/9356920.html