只有一個這一個是反面
只有一行那麼除了兩邊之外都是反面
不然輸出\((N - 2)*(M - 2)\)ios
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define enter putchar('\n') #define space putchar(' ') #define MAXN 100005 //#define ivorysi using namespace std; typedef long long int64; typedef double db; template<class T> void read(T &res) { res = 0;char c = getchar();T f = 1; while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int64 N,M; int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif read(N);read(M); int64 ans = 0; if(N > M) swap(N,M); if(N == 1 && M == 1) {puts("1");enter;} else if(N == 1) { out(M - 2);enter; } else { out((N - 2) * (M - 2));enter; } return 0; }
枚舉模數,顯然模數須要大於K
對於一個模數小於它的\(i - K\)都合法,若是\(K = 0\)那麼是\(i - K - 1\)
對於大於等於它的,咱們找到倍數在\(\lfloor\frac{N}{i}\rfloor - 1\)的部分,而後對於\(\lfloor \frac{N}{i} \rfloor \cdot i + K\)統計到N之間的個數c++
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define enter putchar('\n') #define space putchar(' ') #define MAXN 100005 //#define ivorysi using namespace std; typedef long long int64; typedef double db; template<class T> void read(T &res) { res = 0;char c = getchar();T f = 1; while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int N,K; int64 ans; int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif read(N);read(K); for(int i = 1 ; i <= N ; ++i) { if(i <= K) continue; ans += i - K;if(K == 0) --ans; int t = N / i - 1; ans += t * (i - K); t = N / i * i + K; if(t <= N) ans += N - t + 1; } out(ans);enter; return 0; }
最長降低子序列是由幾個最長上升子序列拼出來的spa
若是最長上升子序列長度爲A
那麼最長降低子序列最多能夠有\(N - A + 1\)個
最少能夠有\(\lceil \frac{N}{A}\rceil\)個,這中間的均可以經過給\(B\)個最長上升子序列分配個數實現code
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <cmath> #include <queue> #include <ctime> #define fi first #define se second #define pii pair<int,int> //#define ivorysi #define mp make_pair #define pb push_back #define enter putchar('\n') #define space putchar(' ') #define MAXN 300005 using namespace std; typedef long long int64; typedef double db; typedef unsigned int u32; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9' ) { res = res * 10 - '0' + c; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int N,A,B; int cnt[MAXN]; void Solve() { read(N);read(A);read(B); int d = (N - 1) / A + 1,u = N - A + 1; if(B > u || B < d) {puts("-1");return;} cnt[1] = A; int t = N - A; for(int i = 2 ; i <= B ; ++i) { cnt[i] = t - A >= B - i ? A : t - (B - i); t -= cnt[i]; } t = N; for(int i = B ; i >= 1 ; --i) { for(int j = t - cnt[i] + 1 ; j <= t ; ++j) { out(j);space; } t -= cnt[i]; } enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; }
若是你有出色的打表技巧能夠經過本題ip
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <cmath> #include <queue> #include <ctime> #define fi first #define se second #define pii pair<int,int> //#define ivorysi #define mp make_pair #define pb push_back #define enter putchar('\n') #define space putchar(' ') #define MAXN 300005 using namespace std; typedef long long int64; typedef double db; typedef unsigned int u32; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9' ) { res = res * 10 - '0' + c; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int N; int dfs(int a,int x) { if(a < x) return 0; if(a % x == 0) return a / x; int t = a / x,h = a % x; //out(a);space;out(t);space;out(h);enter; dfs(a - ((h - 1) / (t + 1) + 1) * (t + 1),x); } void Solve() { read(N); int ans = 0; int a,k; for(int i = 1 ; i <= N ; ++i) { read(a);read(k); ans ^= dfs(a,k); } if(!ans) puts("Aoki"); else puts("Takahashi"); } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; }