#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define pi acos(-1)
#define maxn 111111
#define maxm 11111
#define INF 0x3F3F3F3F
#define eps 1e-8
#define pb push_back
#define mem(a) memset(a,0,sizeof a)
using namespace std;
const long long mod = 1000000007;
/**lyc**/
void init() {
}
int main() {
int m;
int kase = 0;
while(scanf("%d", &m) != EOF) {
int ans = m * log10(2);
printf("Case #%d: %d\n", ++kase, ans);
}
return 0;
}
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define pi acos(-1)
#define maxn 111111
#define maxm 11111
#define INF 0x3F3F3F3F
#define eps 1e-8
#define pb push_back
#define mem(a) memset(a,0,sizeof a)
using namespace std;
const long long mod = 1000000007;
/**lyc**/
void init() {
}
long long n, k;
int main() {
int kase = 0;
while(scanf("%lld%lld", &n, &k) != EOF) {
if(k <= n) {
printf("Case #%d: %lld\n", ++kase, k);
continue;
}
k -= n;
k = k % (2 * (n - 1));
if(k == 0) k = 2 * (n - 1);
if(k <= n - 1) {
printf("Case #%d: %lld\n", ++kase, k);
}
else {
k -= n - 1;
if(k <= n - 2) {
printf("Case #%d: %lld\n", ++kase, k);
}
else {
printf("Case #%d: %lld\n", ++kase, n);
}
}
}
return 0;
}
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define pi acos(-1)
#define maxn 111111
#define maxm 11111
#define INF 0x3F3F3F3F
#define eps 1e-8
#define pb push_back
#define mem(a) memset(a,0,sizeof a)
using namespace std;
const long long mod = 1000000007;
/**lyc**/
void init() {
}
char s[maxn];
int n;
int num[maxn][30];
bool tou[30];
bool vis[30];
int ans[30];
int maxa[maxn];
int temp[maxn];
bool cp(int *a, int *b, int len) {
for(int i = len - 1; i >= 0; i--) {
if(a[i] == b[i]) continue;
if(a[i] > b[i]) return 1;
else return 0;
}
return 1;
}
int main() {
int kase = 0;
while(scanf("%d", &n) != EOF) {
int maxlen = 0;
memset(num, 0, sizeof num);
memset(tou, 0, sizeof tou);
for(int i = 1; i <= n; i++) {
scanf("%s", s);
int len = strlen(s);
maxlen = max(maxlen, len);
tou[s[0] - 'a'] = 1;
reverse(s, s + len);
for(int j = 0; j < len; j++) {
num[j][s[j] - 'a']++;
}
}
int toun = 0;
for(int i = 0; i < 26; i++)
if(tou[i]) toun++;
int fa = 0;///0是否被用
memset(ans, 0, sizeof ans);
memset(vis, 0, sizeof vis);
//cout << "1*************" << endl;
for(int i = 25; i >= 0; i--) {
int pos = -1;
if(fa && !i) break;
memset(maxa, 0, (sizeof maxa[0]) * (maxlen + 10));
for(int k = 0; k <= 25; k++) if(!vis[k]) {
// cout << k << endl;
memset(temp, 0, (sizeof temp[0]) * (maxlen + 10));
long long more = 0;
for(int j = 0; j < maxlen - 1; j++) {
temp[j] = (1LL * num[j][k] * i + more) % 26;
more = (1LL * num[j][k] * i + more) / 26;
}
temp[maxlen - 1] = 1LL*num[maxlen - 1][k] * i + more;
if(cp(temp, maxa, maxlen)) {
swap(temp, maxa);
pos = k;
}
}
// cout << i << " " << pos << endl;
if(!fa && !tou[pos]) {
if(toun == i) {
ans[pos] = 0;
vis[pos] = 1;
i++;
fa = 1;
continue;
}
}
ans[pos] = i;
vis[pos] = 1;
if(tou[pos]) toun--;
}
// cout << "2*************" << endl;
long long tot = 0;
long long bit = 1;
for(int i = 0; i < maxlen; i++) {
for(int j = 0; j < 26; j++) {
tot += 1LL * bit * num[i][j] % mod * ans[j] % mod;
if(tot >= mod) tot -= mod;
}
bit *= 26;
bit %= mod;
}
printf("Case #%d: %lld\n", ++kase, tot);
}
return 0;
}
f(i)=bf(ai)=bbf(aai)=b⋯bf(i)l times b 其中l是i所在a中循环节的长度
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define pi acos(-1)
#define maxn 111111
#define maxm 11111
#define INF 0x3F3F3F3F
#define eps 1e-8
#define pb push_back
#define mem(a) memset(a,0,sizeof a)
using namespace std;
const long long mod = 1000000007;
/**lyc**/
void init() {
}
int n, m;
int a[maxn][2]; //0是a,1是b
int cal[maxn][2]; //0是a,1是b cal[i]为长度为i的循环节有多少个。
bool vis[maxn];
void dfs(int x, int l, int op) {
if(vis[x]) {
cal[l][op]++;
return;
}
vis[x] = 1;
dfs(a[x][op], l + 1, op);
}
int main() {
int kase = 0;
while(scanf("%d%d", &n, &m) != EOF) {
memset(cal, 0, sizeof cal);
for(int i = 0; i < n; i++) {
scanf("%d", &a[i][0]);
}
for(int i = 0; i < m; i++) {
scanf("%d", &a[i][1]);
}
memset(vis, 0, sizeof vis);
for(int i = 0; i < n; i++) if(!vis[i]) {
dfs(i, 0, 0);
}
memset(vis, 0, sizeof vis);
for(int i = 0; i < m; i++) if(!vis[i]) {
dfs(i, 0, 1);
}
long long ans = 1LL;
for(int i = 1; i <= n; i++) if(cal[i][0]) {
long long tot = 0;
int limt = (int)sqrt(i + 0.5);
for(int j = 1; j <= limt; j++) {
if(i % j == 0) {
tot += 1LL * cal[j][1] * j % mod;
tot %= mod;
if(i != j * j) {
tot += 1LL * cal[i / j][1] * (i / j) % mod;
tot %= mod;
}
}
}
for(int j = 1; j <= cal[i][0]; j++) {
ans = (ans * tot) % mod;
}
}
printf("Case #%d: %lld\n", ++kase, ans);
}
return 0;
}
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define pi acos(-1)
#define maxn 111111
#define maxm 11111
#define INF 0x3F3F3F3F
#define eps 1e-8
#define pb push_back
#define mem(a) memset(a,0,sizeof a)
using namespace std;
const long long mod = 1000000007;
/**lyc**/
int n, m, A, B, C;
unsigned a[10001111];
int b[111];
int pos[111];
unsigned ans[111];
unsigned x, y, z;
inline
unsigned rng61() {
unsigned t;
x ^= x << 16;
x ^= x >> 5;
x ^= x << 1;
t = x;
x = y;
y = z;
z = t ^ x ^ y;
return z;
}
bool cmp(int x, int y) {
return b[x] < b[y];
}
int main() {
int kase = 0;
while(scanf("%d%d%d%d%d", &n, &m, &A, &B, &C) != EOF) {
for(int i = 0; i < m; i++) {
scanf("%d", &b[i]);
pos[i] = i;
}
sort(pos, pos + m, cmp);
pos[m] = m;
b[m] = n;
x = A, y = B, z = C;
for(int i = 0; i < n; i++) {
a[i] = rng61();
}
for(int i = m - 1; i >= 0; i--) {
if(i != m - 1 && b[pos[i]] == b[pos[i + 1]]) { ///省下b相同的计算
ans[pos[i]] = ans[pos[i + 1]];
continue;
}
nth_element(a, a + b[pos[i]], a + b[pos[i + 1]]);
///将a数组中这个0-b[pos[i + 1]]-1这个范围里第b[pos[i]]大的数放在第b[pos[i]]-1的位置上
ans[pos[i]] = a[b[pos[i]]];
}
printf("Case #%d:", ++kase);
for(int i = 0; i < m; i++)
printf(" %u", ans[i]);
printf("\n");
}
return 0;
}