#include<iostream>#include<cstring>#include<algorithm>#include<vector>usingnamespace std;typedeflonglong LL;intmain(){LL n;cin >> n;vector<LL> d;for(LL i =1; i * i <= n; i ++)if(n % i ==0){d.push_back(i);if(n / i != i) d.push_back(n / i);}int res =0;for(auto a: d)for(auto b: d)for(auto c: d)if(a * b * c == n)res ++;cout << res << endl;return0;}
答案:2430
路徑
就是一個建邊跑最短路。。比賽時忘了gcd咋寫emm 好像有的用dp來做?
#include<iostream>#include<cstring>#include<algorithm>usingnamespace std;constint N =2200, M = N *50;int n;int h[N], e[M], w[M], ne[M], idx;int q[N], dist[N];bool st[N];intgcd(int a,int b)// 歐幾里得算法{return b ?gcd(b, a % b): a;}voidadd(int a,int b,int c)// 添加一條邊a->b,邊權為c{e[idx]= b, w[idx]= c, ne[idx]= h[a], h[a]= idx ++;}voidspfa()// 求1號點到n號點的最短路距離{int hh =0, tt =0;memset(dist,0x3f,sizeof dist);dist[1]=0;q[tt ++]=1;st[1]=true;while(hh != tt){int t = q[hh ++];if(hh == N) hh =0;st[t]=false;for(int i = h[t]; i !=-1; i = ne[i]){int j = e[i];if(dist[j]> dist[t]+ w[i]){dist[j]= dist[t]+ w[i];if(!st[j])// 如果隊列中已存在j,則不需要將j重復插入{q[tt ++]= j;if(tt == N) tt =0;st[j]=true;}}}}}intmain(){n =2021;memset(h,-1,sizeof h);for(int i =1; i <= n; i ++)for(int j =max(1, i -21); j <=min(n, i +21); j ++){int d =gcd(i, j);add(i, j, i * j / d);}spfa();printf("%d\n", dist[n]);return0;}
答案:10266837
時間顯示
比賽時忘了1s等于多少ms,還好電腦自帶計算器里有時間的進制關系(狗頭🐕)
#include<iostream>#include<cstring>#include<algorithm>usingnamespace std;typedeflonglong LL;intmain(){LL n;cin >> n;n /=1000;n %=86400;int h = n /3600;n %=3600;int m = n /60;int s = n %60;printf("%02d:%02d:%02d\n", h, m, s);return0;}
#include<iostream>#include<cstring>#include<algorithm>usingnamespace std;constint N =110, M =200010, B = M /2;int n, m;int w[N];bool f[N][M];intmain(){scanf("%d",&n);for(int i =1; i <= n; i ++)scanf("%d",&w[i]), m += w[i];f[0][B]=true;for(int i =1; i <= n; i ++)for(int j =-m; j <= m; j ++){f[i][j + B]= f[i -1][j + B];if(j - w[i]>=-m) f[i][j + B]|= f[i -1][j - w[i]+ B];if(j + w[i]<= m) f[i][j + B]|= f[i -1][j + w[i]+ B];}int res =0;for(int j =1; j <= m; j ++)if(f[n][j + B])res ++;printf("%d\n", res);return0;}
#include<iostream>#include<cstring>#include<algorithm>usingnamespace std;typedeflonglong LL;int n;LL C(int a,int b){LL res =1;for(int i = a, j =1; j <= b; i --, j ++){res = res * i / j;if(res > n)return res;}return res;}boolcheck(int k){//C(a,b)//a>=2b,二分a LL l = k *2, r = n;while(l < r){LL mid = l + r >>1;if(C(mid, k)>= n) r = mid;else l = mid +1;}if(C(r, k)!= n)returnfalse;cout << r *(r +1)/2+ k +1<< endl;returntrue;}intmain(){cin >> n;for(int k =16;; k --)if(check(k))break;return0;}