Skip to content

Instantly share code, notes, and snippets.

@redraiment
Created November 16, 2013 11:26
Show Gist options
  • Save redraiment/7499122 to your computer and use it in GitHub Desktop.
Save redraiment/7499122 to your computer and use it in GitHub Desktop.
杭电ACM 2000到2099题
#include <algorithm>
#include <iostream>
#include <cstdlib>
using namespace std;
int main(void) {
char s[4];
while (cin >> s) {
sort(s, s + 3);
cout << s[0] << ' ' << s[1] << ' ' << s[2] << endl;
}
return EXIT_SUCCESS;
}
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main(void) {
double x[2], y[2];
while (scanf("%lf%lf%lf%lf", x, y, x+1, y+1) != EOF) {
printf("%.2f\n", sqrt(pow(x[1] - x[0], 2) + pow(y[1] - y[0], 2)));
}
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define PI 3.1415927
int main(void) {
double r;
while (scanf("%lf", &r) != EOF)
printf("%.3lf\n", 4.0*PI*r*r*r/3.0);
return EXIT_SUCCESS;
}
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main(void) {
double r;
while (scanf("%lf", &r) != EOF)
printf("%.2lf\n", fabs(r));
return EXIT_SUCCESS;
}
#include <math.h>
#include <stdio.h>
int main(void) {
int r;
while (scanf("%d", &r) != EOF) {
if (r < 0)
puts("Score is error!");
else if (r < 60)
puts("E");
else if (r < 70)
puts("D");
else if (r < 80)
puts("C");
else if (r < 90)
puts("B");
else if (r <= 100)
puts("A");
else
puts("Score is error!");
}
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define leap(n) (n % 4 == 0 && (n % 100 != 0 || n % 400 == 0))
int main(void) {
int y, m, d, i, s;
int month[2][13] = {
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
while (scanf("%d/%d/%d", &y, &m, &d) != EOF) {
for (s = 0, i = 1 ; i < m ; i++)
s += month[leap(y)][i];
s += d;
printf("%d\n", s);
}
return EXIT_SUCCESS;
}
#include <stdio.h>
int main(void) {
int n, i, s, t;
while (scanf("%d", &n) != EOF) {
s = 1;
for (i = 0; i < n; i++) {
scanf("%d", &t);
if (t & 1)
s *= t;
}
printf("%d\n", s);
}
return 0;
}
#include <stdlib.h>
#include <stdio.h>
int main(void) {
unsigned int m, n, i, x, y;
while (scanf("%u%u", &m, &n) != EOF) {
if (m > n) {
i = n;
n = m;
m = i;
}
x = y = 0;
for (i = m ; i <= n ; i++)
(i & 1) ? (y += i*i*i) : (x += i*i);
printf("%u %u\n", x, y);
}
return EXIT_SUCCESS;
}
#include <stdio.h>
int main(void)
{
int n, i, a, b, c;
double x;
while (scanf("%d", &n) , n)
{
a = b = c = 0;
for (i = 0 ; i < n ; i++)
{
scanf("%lf", &x);
if (x > 0) c++;
else if (x < 0) a++;
else b++;
}
printf("%d %d %d\n", a, b, c);
}
return 0;
}
#include <math.h>
#include <stdio.h>
int main(void)
{
int n;
double x, s;
while (scanf("%lf%d", &x, &n) != EOF)
{
for(s = 0.0; n--; x = sqrt(x))
s += x;
printf("%.2lf\n", s);
}
return 0;
}
#include<stdio.h>
int main() {
int b, l, c, i;
int a[] = {1, 153, 370, 371, 407};
while (scanf("%d%d", &b, &l) != EOF) {
c = 0;
for (i = 0 ; i < 5 ; i++) {
if (a[i] >= b && a[i] <= l)
printf(c++ ? " %d" : "%d", a[i]);
}
printf(c ? "\n" : "no\n");
}
return 0;
}
#include<stdio.h>
int n;
double rev(int c) {
return c <= n ?( ((c & 1) ? 1.0 : -1.0) / c + rev(c + 1) ): 0;
}
int main() {
int t;
scanf("%d", &t);
while (t-- && scanf("%d", &n))
printf("%.2lf\n", rev(1));
return 0;
}
#include <stdio.h>
int main(void) {
int m, n;
int x[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1
};
while (scanf("%d%d", &m, &n), m || n) {
for (m += 39, n += 39; x[m] && m <= n ; m++);
puts(m > n ? "OK" : "Sorry");
}
return 0;
}
#include <math.h>
#include <stdio.h>
int main(void)
{
int n;
while (scanf("%d", &n) != EOF)
printf("%.0f\n", 3 * pow(2, n - 1) - 2);
return 0;
}
#include <stdio.h>
int main(void)
{
int n, i;
double min, max;
double x, y;
while (scanf("%d", &n) != EOF)
{
scanf("%lf", &x);
min = max = x;
for (i = 1 ; i < n ; i++)
{
scanf("%lf", &y);
x += y;
if (y > max) max = y;
if (y < min) min = y;
}
printf("%.2lf\n", (x - min - max) / (n - 2));
}
return 0;
}
#include <stdio.h>
int main(void)
{
int i, n, m, b, c;
while (scanf("%d%d", &n, &m) != EOF)
{
b = 2;
c = 0;
for (i = 0 ; i < n / m ; i++)
{
printf(c++? " %d": "%d", b + m - 1);
b += m * 2;
}
printf(n % m? " %d\n": "\n", b + n % m - 1);
}
return 0;
}
#include <cstdio>
#include <algorithm>
using namespace std;
int main(void)
{
int i, n;
int f[100], m;
while (scanf("%d", &n), n)
{
m = 0;
for (i = 0 ; i < n ; i++)
{
scanf("%d", f + i);
if (f[i] < f[m]) m = i;
}
swap(f[m], f[0]);
for (i = 0 ; i < n ; i++)
printf("%d%c", f[i], (i < n - 1 ? ' ' : '\n'));
}
return 0;
}
#include <ctype.h>
#include <stdio.h>
int main(void)
{
int n, d;
char c;
scanf("%d%*c", &n);
while (n--)
{
for (d = 0 ; (c = getchar()) != '\n' ;)
{
if (isdigit(c)) d++;
}
printf("%d\n", d);
}
return 0;
}
#include <ctype.h>
#include <stdio.h>
int main(void)
{
int n, i;
int fab[55] = {1, 2, 3, 4, 6};
for (i = 5 ; i < 55 ; i++)
fab[i] = fab[i - 1] + fab[i - 3];
while (scanf("%d", &n), n)
{
printf("%d\n", fab[n - 1]);
}
return 0;
}
#include <stdio.h>
int main(void)
{
int n, i, m, x[101];
while (scanf("%d%d", &n, &m), n || m)
{
for (i = 0 ; i < n ; i++)
scanf("%d", x + i);
for (i = n ; i && x[i - 1] > m ; i--)
x[i] = x[i - 1];
x[i] = m;
for (i = 0 ; i < n + 1 ; i++)
printf("%d%c", x[i], (i - n ? ' ' : '\n'));
}
return 0;
}
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int cmp(const int *a, const int *b)
{
return abs(*b) - abs(*a);
}
int main(void)
{
int n, i, x[101];
while (scanf("%d", &n), n)
{
for (i = 0 ; i < n ; i++)
scanf("%d", x + i);
qsort(x, n, sizeof(int), cmp);
for (i = 0 ; i < n ; i++)
printf("%d%c", x[i], (i != n - 1 ? ' ' : '\n'));
}
return 0;
}
#include <stdio.h>
int main(void)
{
int n, i, j, x, sum;
int money[] = { 100, 50, 10, 5, 2, 1 };
while (scanf("%d", &n), n) {
sum = 0;
for (i = 0 ; i < n ; i++) {
scanf("%d", &x);
for (j = 0; x; j++) {
sum += x / money[j];
x %= money[j];
}
}
printf("%d\n", sum);
}
return 0;
}
#include <math.h>
#include <stdio.h>
int main(void)
{
int i, j;
int n, m;
int x, y;
double a, t;
while (scanf("%d%d", &n, &m) != EOF)
{
a = x = y = 0;
for (i = 0 ; i < n ; i++)
{
for (j = 0 ; j < m ; j++)
{
scanf("%lf", &t);
if (fabs(t) > fabs(a))
{
a = t;
x = i;
y = j;
}
}
}
printf("%d %d %.0f\n", x + 1, y + 1, a);
}
return 0;
}
#include <stdio.h>
#include <string.h>
int main(void)
{
int n, m;
int i, j;
int t, d;
int s[50];
int c[5];
int sc[50][5];
while (scanf("%d%d", &n, &m) != EOF)
{
memset(s, 0, sizeof(s));
memset(c, 0, sizeof(c));
memset(sc, 0, sizeof(sc));
for (i = 0 ; i < n ; i++)
{
for (j = 0 ; j < m ; j++)
{
scanf("%d", &sc[i][j]);
c[j] += sc[i][j];
s[i] += sc[i][j];
}
}
for (i = 0 ; i < n ; i++)
printf("%.2lf%c", s[i] * 1.0 / m, i < n - 1 ? ' ' : ' \n');
for (i = 0 ; i < m ; i++)
printf("%.2lf%c", c[i] * 1.0 / n, i < m - 1 ? ' ' : ' \n');
for (t = i = 0 ; i < n ; i++)
{
for (d = 1, j = 0 ; j < m ; j++)
{
if (sc[i][j] < 1.0 * c[j] / n)
{
d = 0;
break;
}
}
if (d) t++;
}
printf("%d\n\n", t);
}
return 0;
}
#include <ctype.h>
#include <stdio.h>
int main(void)
{
int n, d, i;
char sym[64];
scanf("%d%*c", &n);
while (n--)
{
gets(sym);
if (sym[0] != '_' && !isalpha(sym[0]))
{
puts("no");
continue;
}
for (d = i = 1 ; sym[i] ; i++)
{
if (!isalnum(sym[i]) && sym[i] != '_')
{
d = 0;
break;
}
}
puts(d ? "yes" : "no");
}
return 0;
}
#include <stdio.h>
int main(void)
{
char t[128];
char max;
int i;
while (gets(t))
{
for (max = i = 0 ; t[i] ; i++)
{
if (t[i] > max)
max = t[i];
}
for (i = 0 ; t[i] ; i++)
{
putchar(t[i]);
if (t[i] == max)
printf("%s", "(max)");
}
putchar('\n');
}
return 0;
}
#include <ctype.h>
#include <stdio.h>
int main(void)
{
char t[128] = {' '};
int i;
while (gets(t + 1))
{
for (i = 1 ; t[i] ; i++)
putchar((isalpha(t[i]) && t[i-1] == ' ') ? toupper(t[i]) : t[i]);
putchar('\n');
}
return 0;
}
#include <ctype.h>
#include <stdio.h>
int main(void)
{
int n;
int y[5];
char c;
scanf("%d%*c", &n);
while (n--)
{
y[0] = y[1] = y[2] = y[3] = y[4] = 0;
while ((c = getchar()) != '\n')
{
switch (tolower(c))
{
case 'a':
y[0]++;
break;
case 'e':
y[1]++;
break;
case 'i':
y[2]++;
break;
case 'o':
y[3]++;
break;
case 'u':
y[4]++;
break;
default :
break;
}
}
printf("a:%d\n", y[0]);
printf("e:%d\n", y[1]);
printf("i:%d\n", y[2]);
printf("o:%d\n", y[3]);
printf("u:%d\n", y[4]);
if (n) putchar('\n');
}
return 0;
}
#include<stdio.h>
typedef unsigned long UL;
UL gcd(UL u, UL v)
{
int remainder;
remainder = u % v;
while(remainder)
{
u = v;
v = remainder;
remainder = u % v;
}
return v;
}
UL lcm(UL u, UL v)
{
return u * v / gcd(u, v);
}
int main(void)
{
int n;
UL u;
UL res;
while (scanf("%d", &n) != EOF)
{
res = 1;
while (n--)
{
scanf("%lu", &u);
res = lcm(res, u);
}
printf("%lu\n", res);
}
return 0;
}
#include <stdio.h>
#include <string.h>
int main(void)
{
int n;
char s[1024];
char t[1024];
scanf("%d%*c", &n);
while (n--)
{
gets(s);
strcpy(t, s);
strrev(s);
puts(strcmp(t, s) ? "no" : "yes");
}
return 0;
}
#include <stdio.h>
#include <string.h>
int main(void)
{
int n;
int count;
char c;
scanf("%d%*c", &n);
while (n--)
{
count = 0;
while ((c = getchar()) != '\n')
{
if (c < 0)
count++;
}
printf("%d\n", count / 2);
}
return 0;
}
#include <stdio.h>
#include <string.h>
void ttor(int n, int r)
{
if (n)
{
ttor(n / r, r);
printf("%c", n % r > 9 ? n % r - 10 + 'A' : n % r + '0');
}
}
int main(void)
{
int n;
int r;
while (scanf("%d%d", &n, &r) != EOF)
{
if (n > 0)
ttor(n, r);
else if (!n)
putchar('0');
else
{
putchar('-');
ttor(-n, r);
}
putchar('\n');
}
return 0;
}
#include <stdio.h>
#include <string.h>
int main(void)
{
int i, j, n;
int YanHui[32];
while (scanf("%d", &n) != EOF)
{
memset(YanHui, 0, sizeof(YanHui));
YanHui[0] = 1;
for (i = 0 ; i < n ; i++)
{
printf("%d", 1);
for (j = i ; j ; j--)
YanHui[j] += YanHui[j - 1];
for (j = 1 ; j <= i ; j++)
printf(" %d", YanHui[j]);
putchar('\n');
}
putchar('\n');
}
return 0;
}
#include <stdio.h>
int main(void)
{
int n, i;
int t[6];
scanf("%d", &n);
while (n--)
{
for (i = 0 ; i < 6 ; i++)
scanf("%d", t + i);
t[1] += (t[2] + t[5]) / 60;
t[2] = (t[2] + t[5]) % 60;
t[0] += (t[1] + t[4]) / 60;
t[1] = (t[1] + t[4]) % 60;
t[0] += t[3];
printf("%d %d %d\n", t[0], t[1], t[2]);
}
return 0;
}
#include <set>
#include <cstdio>
using namespace std;
int main(void)
{
int n, m, t;
set <int> s;
set <int>::iterator it;
while (scanf("%d%d", &n, &m), n + m)
{
while (n--)
{
scanf("%d", &t);
s.insert(t);
}
while (m--)
{
scanf("%d", &t);
if (s.count(t)) s.erase(t);
}
for (it = s.begin(); it != s.end(); it++)
printf("%d ", *it);
printf(s.size() ? "\n" : "NULL\n");
s.clear();
}
return 0;
}
#include <stdio.h>
int mi(int n, int m)
{
return m?(m%2?(mi(n, m/2)*mi(n, m/2)*(n%1000))%1000:(mi(n,m/2)*mi(n,m/2))%1000):1;
}
int main(void)
{
int n, m;
while(scanf("%d%d", &n, &m), n+m)
printf("%d\n", mi(n, m));
return 0;
}
#include <math.h>
#include <stdio.h>
int main(void)
{
int x[3], y[3], n;
double sum;
while (scanf("%d", &n), n)
{
scanf("%d%d", x, y);
x[2] = x[0]; y[2] = y[0];
sum = 0.0;
while (--n)
{
scanf("%d%d", x+1, y+1);
sum += x[0]*y[1] - x[1]*y[0];
x[0] = x[1]; y[0] = y[1];
}
sum += x[0]*y[2] - x[2]*y[0];
printf("%.1f\n", sum / 2.0);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
struct c
{
int x;
int y;
int ord;
}d[100];
int cmp(const struct c *a, const struct c *b)
{
if ((*a).x == (*b).x)
return (*a).y - (*b).y;
else
return (*a).x - (*b).x;
}
int main(void)
{
int i, j, n, max;
while (scanf("%d", &n), n)
{
for (max = i = 0; i < n; i++)
{
scanf("%d%d", &d[i].x, &d[i].y);
d[i].ord = 1;
}
qsort(d, n, sizeof(struct c), cmp);
d[n-1].ord = 1;
for (i = n - 2; i >= 0; i--)
{
for (j = i + 1; j < n; j++)
{
if (d[i].y <= d[j].x && d[i].ord < d[j].ord + 1)
d[i].ord = d[j].ord + 1;
}
if (max < d[i].ord)
max = d[i].ord;
}
printf("%d\n", max);
}
return 0;
}
#include <stdio.h>
int main(void)
{
int n;
double a, b, c;
scanf("%d", &n);
while (n-- && scanf("%lf%lf%lf", &a, &b, &c))
puts(a + b > c && a + c > b && b + c > a ? "YES" : "NO");
return 0;
}
#include <stdio.h>
int A(int n)
{
int i,sum = 1;
for (i = 2; i <= n / 2; i++)
if (n % i == 0)
sum += i;
return sum;
}
int main(void)
{
int n, a, b;
scanf("%d", &n);
while (n-- && scanf("%d%d", &a, &b))
puts(A(a) == b && A(b) == a ? "YES" : "NO");
return 0;
}
#include <stdio.h>
int main(void)
{
int i, n;
__int64 m[41] = {0, 1};
for (i = 2; i < 41; i++)
m[i] = m[i-1] + m[i-2];
scanf("%d", &n);
while (n-- && scanf("%d", &i))
printf("%I64d\n", m[i]);
return 0;
}
#include <math.h>
#include <stdio.h>
int main(void)
{
int n, t;
scanf("%d", &t);
while(t-- && scanf("%d", &n))
printf("%.0f\n", pow(2, n) + 2);
return 0;
}
#include <ctype.h>
#include <stdio.h>
int main(void)
{
int n, a[6];
char c;
scanf("%d%*c", &n);
while (n--)
{
a[0] = a[1] = a[2] = a[3] = a[4] = a[5] = 0;
while ((c = getchar()) != '\n')
{
if (isupper(c))
a[0] = a[5]++;
else if (islower(c))
a[1] = a[5]++;
else if (isdigit(c))
a[2] = a[5]++;
else
a[3] = a[5]++;
}
if (a[0]) a[4]++;
if (a[1]) a[4]++;
if (a[2]) a[4]++;
if (a[3]) a[4]++;
puts(a[4] > 2 && a[5] > 7 && a[5] <17 ? "YES" : "NO");
}
return 0;
}
#include <stdio.h>
int main(void)
{
int i, j, n;
__int64 d[51] = {1, 1, 2,};
for (i = 3; i < 51; i++)
d[i] = d[i-1] + d[i-2];
scanf("%d", &n);
while (n-- && scanf("%d%d", &i, &j) != EOF)
printf("%I64d\n", i > j ? 0 : d[j-i]);
return 0;
}
#include <math.h>
#include <stdio.h>
int main(void)
{
int i;
__int64 d[51] = {0, 3, 6, 6};
for (i = 4; i < 51; i++)
d[i] = d[i-1] + 2*d[i-2];
while (scanf("%d", &i) != EOF)
printf("%I64d\n", d[i]);
return 0;
}
#include <math.h>
#include <stdio.h>
int main(void)
{
int i;
__int64 d[51] = {1, 1, 2,};
for (i = 3; i < 51; i++)
d[i] = d[i-1] + d[i-2];
while (scanf("%d", &i) != EOF)
printf("%I64d\n", d[i]);
return 0;
}
#include <math.h>
#include <stdio.h>
int main(void)
{
int i;
__int64 d[41][2] = {
{0, 0}, {1, 2}
};
for (i = 2; i < 41; i++)
{
d[i][0] = d[i-1][1];
d[i][1] = 2 * (d[i-1][0] + d[i-1][1]);
}
while (scanf("%d", &i) != EOF)
printf("%I64d\n", d[i][0] + d[i][1]);
return 0;
}
#include <math.h>
#include <stdio.h>
int main(void)
{
int i, n;
__int64 d[21][2] = {
{1, 0}, {1, 0},
{2, 1}, {6, 2}
};
for (i = 4; i < 21; i++)
{
d[i][0] = i * d[i-1][0];
d[i][1] = (i - 1) * (d[i-1][1] + d[i-2][1]);
}
scanf("%d", &n);
while (n-- && scanf("%d", &i))
printf("%.2f%%\n", d[i][1]*100.0/d[i][0]);
return 0;
}
#include <stdio.h>
int main(void)
{
int i, m, n;
__int64 a[21][2] = {{1,0},{1,0},{2,1},{6,2}};
for (i = 4; i < 21; i++)
{
a[i][0] = i * a[i-1][0];
a[i][1] = (i-1) * (a[i-1][1] + a[i-2][1]);
}
scanf("%d", &i);
while (i-- && scanf("%d%d", &n, &m))
printf("%I64d\n", a[n][0]/a[m][0]/a[n-m][0]*a[m][1]);
return 0;
}
#include <stdio.h>
int main(void)
{
int n, i;
scanf("%d", &i);
while (i-- && scanf("%d", &n))
printf("%d\n", 2*n*n-n+1);
return 0;
}
#include <stdio.h>
void TtoB(int n)
{
if (n)
{
TtoB(n >> 1);
printf("%d", n & 1);
}
}
int main(void)
{
int n;
while (scanf("%d", &n) != EOF)
{
TtoB(n);
putchar('\n');
}
return 0;
}
#include <stdio.h>
int main(void)
{
int w, h, i, j;
while (scanf("%d%d", &w, &h) != EOF)
{
putchar('+');
for (i = 0; i < w; i++)
putchar('-');
putchar('+');
putchar('\n');
for (j = 0; j < h; j++)
{
putchar('|');
for (i = 0; i < w; i++)
putchar(' ');
putchar('|');
putchar('\n');
}
putchar('+');
for (i = 0; i < w; i++)
putchar('-');
printf("+\n\n");
}
return 0;
}
#include <math.h>
#include <stdio.h>
#define S(x) (((int)x)*((int)x))
int main(void)
{
int n;
while (scanf("%d", &n) != EOF)
printf("%d\n", S(sqrt(n)) == n);
return 0;
}
#include <stdio.h>
#include <string.h>
void A(char *s)
{
int len = strlen(s);
char *p = s + len - 1;
if (strchr(s, '.'))
while (*p == '0') *p-- = 0;
if (*p == '.') *p = 0;
}
int main(void)
{
char *pa, *pb;
char a[100024], b[100024];
while (scanf("%s%s", &a, &b) != EOF)
{
pa = a; pb = b;
while (*pa == '0') pa++;
while (*pb == '0') pb++;
A(pa); A(pb);
puts(strcmp(pa, pb) ? "NO" : "YES");
}
return 0;
}
#include <stdio.h>
int main()
{
int n, a;
char c;
scanf("%d%*c", &n);
while (n-- && scanf("%c%d%*c", &c, &a))
printf("%d\n", a + (c < 97 ? c - 'A' + 1 : 'a' - c - 1));
return 0;
}
#include <cstdio>
#include <algorithm>
using namespace std;
int main(void)
{
int i;
double a[2], b[2];
double x[4], y[4];
while (scanf("%lf%lf", x, y) != EOF)
{
for (i = 1; i < 4; i++)
scanf("%lf%lf", x+i, y+i);
if (x[0] > x[1]) swap(x[0], x[1]);
if (y[0] > y[1]) swap(y[0], y[1]);
if (x[2] > x[3]) swap(x[2], x[3]);
if (y[2] > y[3]) swap(y[2], y[3]);
a[0] = x[0] > x[2] ? x[0] : x[2];
a[1] = x[1] < x[3] ? x[1] : x[3];
b[0] = y[0] > y[2] ? y[0] : y[2];
b[1] = y[1] < y[3] ? y[1] : y[3];
printf("%.2f\n", a[0]<a[1] && b[0]<b[1]? (b[1]-b[0])*(a[1]-a[0]) : 0);
}
return 0;
}
#include<stdio.h>
int main(void)
{
__int64 a, b;
while(scanf("%I64x%I64X", &a, &b) != EOF)
printf(a+b<0?"-%I64X\n":"%I64X\n", a+b<0?-a-b:a+b);
return 0;
}
#include<stdio.h>
int main()
{
int n, m, i;
while (scanf("%d%d", &m, &n), m+n)
{
for (i = 1; n/i-(i-1)/2>0; i++);
for(i--; i && n/i+i/2 <= m; i--)
{
if((n-n/i*i)*2 == i)
printf("[%d,%d]\n", n/i-(i-1)/2, n/i+i/2);
if(!(n%i) && i%2)
printf("[%d,%d]\n", n/i-(i-1)/2, n/i+i/2);
}
putchar('\n');
}
return 0;
}
#include <stdio.h>
int main(void)
{
int i, j, p[102];
int l, n, c, t;
int vr, v1, v2;
int len;
double dp[102], min, e;
while (scanf("%d", &l) != EOF)
{
scanf("%d%d%d", &n, &c, &t);
scanf("%d%d%d", &vr, &v1, &v2);
dp[0] = p[0] = 0;
for (i = 1; i <= n; i++)
scanf("%d", p + i);
p[i] = l;
for (i = 1; i < n+2; i++)
{
min = 0xffffff;
for (j = 0; j < i; j++)
{
len = p[i] - p[j];
e = len > c ? 1.0 * c / v1 + (len - c + 0.0) / v2 : 1.0 * len / v1;
e += dp[j];
if (j) e += t;
if (min > e) min = e;
}
dp[i] = min;
}
puts(1.0 * l / vr > dp[n+1] ? "What a pity rabbit!" : "Good job,rabbit!");
}
return 0;
}
#include <stdio.h>
int main(void)
{
int t, n, s1, s2;
scanf("%d", &t);
while (t-- && scanf("%d%d%d", &n, &s1, &s2))
{
s1 += n > 6 ? 8 * (n - 6) : 0;
s1 += n > 6 ? 27 : n * (15 - n) / 2;
puts(s1 >= s2 ? "Yes" : "No");
}
return 0;
}
#include <stdio.h>
int main(void)
{
int i, t, n;
double s[2], c[2];
scanf("%d", &t);
while (t-- && scanf("%d", &n))
{
for (s[1]=c[1]=i=0; n--; )
{
scanf("%*s%lf%lf", c, s);
if (i) continue;
if (s[0] < 60 && s[0] >= 0) i = 1;
s[1] += s[0]*c[0];
c[1] += c[0];
}
printf(i?"Sorry!\n":"%.2f\n", s[1]/c[1]);
if (t) putchar('\n');
}
return 0;
}
#include <stdio.h>
int main(void)
{
int i, n, s[21];
__int64 m, t;
__int64 c[21] = {0};
for (i = 1; i < 21; i++)
c[i] = c[i-1] * (i - 1) + 1;
while (scanf("%d%I64d", &n, &m) != EOF)
{
for (i = 0; i < 21; i++)
s[i] = (int)i;
while (n-- && m)
{
if (t = m / c[n+1] + ((m % c[n+1]) ? 1 : 0))
{
printf("%d", s[t]);
for (i = (int)t; i <= n; s[i]=s[i+1], i++);
m -= (t - 1) * c[i] + 1;
putchar(m ? ' ' : '\n');
}
}
}
return 0;
}
#include <stack>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef struct node
{
int ord;
node * next;
}Node;
const int size = 512 + 1;
Node list[size];
int X[size];
int Y[size];
bool visit[size];
int size_x;
int size_y;
stack <int> stk;
void init()
{
int i;
for (i = 1; i <= size_x; i++)
list[i].next = NULL;
memset(X, 0, (size_x + 1) * sizeof(int));
memset(Y, 0, (size_y + 1) * sizeof(int));
}
void input(int len)
{
int i;
int x;
int y;
Node* p;
for (i = 0; i < len; i++)
{
scanf("%d%d", &x, &y);
p = new Node;
p->ord = y;
p->next = list[x].next;
list[x].next = p;
}
}
bool dfs(int x)
{
Node* p;
stk.push(x);
for (p = list[x].next; p; p = p->next)
{
if (!visit[p->ord])
{
visit[p->ord] = true;
stk.push(p->ord);
if (!Y[p->ord] || dfs(Y[p->ord]))
return true;
else
stk.pop();
}
}
stk.pop();
return false;
}
void solve()
{
int i;
int top;
for (i = 1; i <= size_x; i++)
{
while (!stk.empty()) stk.pop();
memset(visit, false, size_y + 1);
if (dfs(i))
{
while (!stk.empty())
{
top = stk.top();
stk.pop();
Y[top] = stk.top();
X[stk.top()] = top;
stk.pop();
}
}
}
}
void output()
{
int i;
int count = 0;
Node* p;
for (i = 1; i <= size_x; i++)
{
if (X[i]) count++;
while (p = list[i].next)
{
list[i].next = p->next;
delete p;
}
}
cout << count << endl;
}
int main(void)
{
int n;
while (scanf("%d", &n), n)
{
scanf("%d%d", &size_x, &size_y);
init();
input(n);
solve();
output();
while (!stk.empty()) stk.pop();
}
return 0;
}
#include <math.h>
#include <stdio.h>
int main(void)
{
int n;
while (scanf("%d", &n) != EOF)
printf("%.0f\n", pow(3, n) - 1);
return 0;
}
#include <stdio.h>
int main(void)
{
__int64 n;
int c, t;
int d[] = {
4, 8,16,32,64,28,56,12,24,48,
96,92,84,68,36,72,44,88,76,52
};
while (scanf("%d", &t), t)
{
for (c = 1; c <= t; c++)
{
scanf("%I64d", &n);
printf("Case %d: %d\n", c, n<3?(n<2?2:6):(d[(2*n-4)%20]+d[(n-3)%20])%100);
}
putchar('\n');
}
return 0;
}
#include <stdio.h>
#define Max 99999
int mp[1001][1001];
int main(void)
{
int i, j, k;
int x, y, cost;
int len, min;
int T, S, D;
int visit[1024];
while (scanf("%d%d%d", &T, &S, &D) != EOF)
{
for (i = 0; i < 1001; i++)
{
for (j = 0; j < 1001; j++)
mp[i][j] = Max;
}
len = 0;
for (i = 0; i < T; i++)
{
scanf("%d%d%d", &x, &y, &cost);
if (mp[x][y] > cost) mp[x][y] = mp[y][x] = cost;
if (len < x) len = x;
if (len < y) len = y;
}
for (i = 0; i < S; i++)
{
scanf("%d", &x);
mp[0][x] = 0;
}
for (i = 0; i <= len; visit[i++] = false);
for (i = 1; i <= len; i++)
{
min = Max;
for (j = 1; j <= len; j++)
{
if (!visit[j] && min > mp[0][j])
{
min = mp[0][j];
k = j;
}
}
if (min == Max) break;
visit[k] = true;
for (j = 1; j <= len; j++)
{
if (!visit[j] && mp[0][j] > mp[0][k] + mp[k][j])
mp[0][j] = mp[0][k] + mp[k][j];
}
}
min = Max;
for (i = 0; i < D; i++)
{
scanf("%d", &x);
if (min > mp[0][x])
min = mp[0][x];
}
printf("%d\n", min);
}
return 0;
}
#include <stdio.h>
int main(void)
{
int i, j;
__int64 a[36] = {1};
__int64 b[36] = {0};
for (i = 1; i < 36; i++)
{
for (j = 1; j < i; j++)
a[j] += a[j-1];
b[i] = a[i] = a[i-1];
}
for (j = 1; scanf("%d", &i), i+1; j++)
printf("%d %d %I64d\n",j, i, 2 * b[i]);
return 0;
}
#include <stdio.h>
int main(void)
{
int i, n;
double s;
double d[26][2] = {{1,1},{1,0},{2,1},{6,2}};
for (i = 4; i < 26; i++) {
d[i][0] = i * d[i-1][0];
d[i][1] = (i - 1) * (d[i-1][1] + d[i-2][1]);
}
while (scanf("%d", &n), n) {
for (s = 0, i = n/2; i >= 0; i--)
s += 1.0*d[n][0]/d[i][0]/d[n-i][0]*d[i][1];
printf("%.lf\n", s);
}
return 0;
}
#include <stdio.h>
int main(void)
{
int n, d[251] = {0};
int c1, c5, c10, c25, c50;
for (n = 0; n < 251; n++)
for (c50 = 0; c50 * 50 <= n; c50++)
for (c25 = 0; c50 * 50 + c25 * 25 <= n; c25++)
for (c10 = 0; c50 * 50 + c25 * 25 + c10 * 10 <= n; c10++)
for (c5 = 0; c50 * 50 + c25 * 25 + c10 * 10 + c5 * 5 <= n; c5++)
{
c1 = n - (c50 * 50 + c25 * 25 + c10 * 10 + c5 * 5);
if (c1 + c5 + c10 + c25 + c50 <= 100) d[n]++;
}
while (scanf("%d", &n) != EOF)
printf("%d\n", d[n]);
return 0;
}
#include <stdio.h>
int main(void)
{
int i;
__int64 f[51]={0, 1};
for(i = 2; i < 51; i++)
f[i] = f[i-1] + f[i-2];
while(scanf("%d", &i), i + 1)
printf("%I64d\n", f[i]);
return 0;
}
#include <stdio.h>
int main(void)
{
int t, n;
double c, b;
scanf("%d", &t);
while (t-- && scanf("%d", &n))
{
c = 0;
while (n-- && scanf("%lf", &b))
if (c < b) c = b;
printf("%.2f\n", c);
}
return 0;
}
#include <set>
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int main(void)
{
set <string> st;
string s = "";
char c;
while ((c = getchar()) != '#')
{
s += c;
while (c != '\n')
{
while ((c = getchar()) != ' ' && c != '\n')
s += c;
if (s.length()) st.insert(s);
s = "";
}
cout << st.size() << endl;
st.clear();
}
return 0;
}
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(void)
{
int n, x[3], y[3];
double s;
scanf("%d", &n);
while (n-- && scanf("%d%d%d%d", x, y, x+1, y+1))
{
if ((x[2] = x[0]+y[0]) > (y[2] = x[1]+y[1]))
{
swap(x[0], x[1]);
swap(y[0], y[1]);
swap(x[2], y[2]);
}
if (x[2] == y[2])
{
printf("%.3f\n", sqrt(pow(x[0]-x[1], 2)+pow(y[0]-y[1], 2)));
}
else
{
s = sqrt((double)2.0)*(x[2] + x[1] - x[0] + y[2]*(y[2]-1)/2.0 - x[2]*(x[2]+1)/2.0);
for (; x[2] < y[2]; x[2]++)
s += sqrt((double)2*x[2]*x[2]+2*x[2]+1);
printf("%.3f\n", s);
}
}
return 0;
}
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
char a[81][81];
void eva(int x, char c)
{
int i = x;
int j = x;
if(2*x>n) a[i][j]=c;
else
{
for(;j<=n-x;j++) a[i][j]=c;
for(;i<=n-x;i++) a[i][j]=c;
for(;j>x;j--) a[i][j]=c;
for(;i>x;i--) a[i][j]=c;
}
}
int main(void)
{
int i, j, t = 0;
char c[2][2];
while (scanf("%d%s%s", &n, c, c+1) != EOF)
{
if (t++) putchar('\n');
if (n == 1)
{
printf("%c\n", c[0][0]);
continue;
}
memset(a, 0, sizeof(a));
if (!(n/2%2)) swap(c[0][0], c[1][0]);
for (i=1; i<=n/2+n%2; eva(i, c[i&1][0]), i++);
a[1][1] = ' ';a[1][n] = ' ';
a[n][1] = ' ';a[n][n] = ' ';
for(i=1;i<=n;i++)
{
for(j=1;a[i][j];j++)
putchar(a[i][j]);
putchar('\n');
}
}
return 0;
}
#include<stdio.h>
int main(void)
{
int n, a, b;
scanf("%d", &n);
while(n-- && scanf("%d%d", &a, &b))
puts(a % b ? "NO" : "YES");
return 0;
}
#include <math.h>
#include <stdio.h>
int main(void)
{
int n, t;
scanf("%d", &t);
while (t-- && scanf("%d", &n))
printf("%.0f\n", pow(3, n-1) + 1);
return 0;
}
#include <math.h>
#include <stdio.h>
int main(void)
{
int n;
double h, m, s;
scanf("%d", &n);
while (n-- && scanf("%lf%lf%lf", &h, &m, &s))
{
if (h > 12) h -= 12;
printf("%d\n", (h=fabs(30*h-11*m/2-11*s/120))>180?(int)(360-h):(int)h);
}
return 0;
}
#include <math.h>
#include <stdio.h>
int main(void)
{
int n, t;
scanf("%d", &t);
while (t-- && scanf("%d", &n))
printf("%.0f\n", pow(3, n-1) + 1);
return 0;
}
#include <stdio.h>
int main(void)
{
int t, n, c, m, i;
scanf("%d", &t);
while (t-- && scanf("%d%*d", &n))
{
for (m = 100, i = 0; i < n; i++)
{
scanf("%d", &c);
if (c < m) m = c;
}
printf("%d\n", (100-m)*(100-m));
}
return 0;
}
#include <stdio.h>
int main(void)
{
int c[9], k, n, i;
int count;
int t[9], a, b;
int total = 40;
scanf("%d", &k);
while (k-- && scanf("%d%d", &total, &n))
{
for (count = i = 0; i < 9; t[i++] = 0);
for (i = 0; i < n; i++)
{
scanf("%d%d", &a, &b);
t[a] = b;
}
for (c[8] = 0; c[8] <= t[8] && c[8] * 8 <= total; c[8]++)
for (c[7] = 0; c[7] <= t[7] && c[8] * 8 + c[7] * 7 <= total; c[7]++)
for (c[6] = 0; c[6] <= t[6] && c[8] * 8 + c[7] * 7 + c[6] * 6 <= total; c[6]++)
for (c[5] = 0; c[5] <= t[5] && c[8] * 8 + c[7] * 7 + c[6] * 6 + c[5] * 5 <= total; c[5]++)
for (c[4] = 0; c[4] <= t[4] && c[8] * 8 + c[7] * 7 + c[6] * 6 + c[5] * 5 + c[4] * 4 <= total; c[4]++)
for (c[3] = 0; c[3] <= t[3] && c[8] * 8 + c[7] * 7 + c[6] * 6 + c[5] * 5 + c[4] * 4 + c[3] * 3 <= total; c[3]++)
for (c[2] = 0; c[2] <= t[2] && c[8] * 8 + c[7] * 7 + c[6] * 6 + c[5] * 5 + c[4] * 4 + c[3] * 3 + c[2] * 2 <= total; c[2]++)
{
c[1] = total - (c[8] * 8 + c[7] * 7 + c[6] * 6 + c[5] * 5 + c[4] * 4 + c[3] * 3 + c[2] * 2);
if (c[1] >= 0 && c[1] <= t[1]) count++;
}
printf("%d\n", count);
}
return 0;
}
#include <math.h>
#include <stdio.h>
int main(void)
{
int n;
double x[2], y[2], t;
scanf("%d", &n);
while (n-- && scanf("%lf%lf%lf%lf", x, y, x+1, y+1))
printf("%.2f\n", (t=asin(fabs(x[0]*y[1]-x[1]*y[0])/sqrt(x[0]*x[0]+y[0]*y[0])/sqrt(x[1]*x[1]+y[1]*y[1]))/acos(-1)*180)?x[0]*x[1]<=0&&y[0]*y[1]<=0?180-t:t:x[0]*x[1]<0?180:0);
return 0;
}
#include <stdio.h>
int main(void)
{
int i, n;
char c;
scanf("%d%*c", &n);
while (n--)
{
putchar('6');
for (i = 0; i < 12; i++)
{
if ((c = getchar()) && i > 5)
putchar(c);
}
}
return 0;
}
#include <stdio.h>
#include <string.h>
int main(void)
{
int i, j, k, t, x;
int n[2][51];
scanf("%d", &t);
while (t--)
{
memset(n[0], 0, sizeof(n[0]));
n[0][0] = 1;
for (i = 1; i < 27; i++)
{
scanf("%d", &x);
if (!x)
{
for (j = 0; j < 51; j++)
n[i % 2][j] = n[!(i%2)][j];
continue;
}
memset(n[i % 2], 0, sizeof(n[0]));
for (j = 0; j < 51 && j <= x * i; j += i)
{
for (k = 0; k + j < 51 ; k++)
{
if (n[!(i%2)][k])
n[i % 2][k + j] += n[!(i%2)][k];
}
}
}
for (x = 0, i = 1; i < 51; i++)
x += n[0][i];
printf("%d\n", x);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int cmp(const int *a, const int *b)
{
return *a - *b;
}
int main(void)
{
int m, n, i, t, d[500];
scanf("%d", &m);
while (m--)
{
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", d + i);
qsort(d, i, sizeof(int), cmp);
for (t = i = 0; i < n / 2; i++)
t += d[n / 2] - d[i];
for (i++; i < n; i++)
t += d[i] - d[n / 2];
printf("%d\n", t);
}
return 0;
}
#include <stdio.h>
int main(void)
{
int t[5600];
int n, i, j, c;
scanf("%d",&c);
while (c--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
for(j=0;j<=i;j++)
scanf("%d",&t[(i+1)*(i+2)/2+j-1]);
for(i=n-2;i>=0;i--)
for(j=0;j<=i;j++)
t[(i+1)*(i+2)/2+j-1]+=t[(i+3)*(i+2)/2+j-1]>t[(i+3)*(i+2)/2+j]?t[(i+3)*(i+2)/2+j-1]:t[(i+3)*(i+2)/2+j];
printf("%d\n",t[0]);
}
return 0;
}
#include <stdio.h>
int main(void)
{
int n, i;
__int64 g[34] = {1};
__int64 d[34] = {0};
for (i = 1; i < 34; i++)
{
g[i] = 3 * g[i - 1] + 2 * d[i - 1];
d[i] = g[i - 1] + d[i - 1];
}
while (scanf("%d", &n), n != -1)
printf("%I64d, %I64d\n", g[n], d[n]);
return 0;
}
#include <stdio.h>
int main(void)
{
int n, i;
double a0, an1, a1;
double c[3000];
while (scanf("%d", &n) != EOF)
{
scanf("%lf%lf", &a0, &an1);
for (i = 0; i < n; i++)
scanf("%lf", c + i);
a1 = n * a0 + an1;
for (i = 1; i <= n; i++)
a1 -= 2 * i * c[n - i];
printf("%.2f\n", a1 / (n + 1));
}
return 0;
}
#include <stdio.h>
#include <string.h>
int main(void)
{
int len, c;
char *p;
char a[1001], b[1001];
while (scanf("%s", a), a[0] != '#')
{
scanf("%s", b);
len = strlen(b);
for (c = 0, p = a; p = strstr(p, b); c++,p += len);
printf("%d\n", c);
}
return 0;
}
#include <stdio.h>
int main(void)
{
int n, i, s, t, c = 0;
int a[50];
while (scanf("%d", &n), n)
{
if (c++) putchar('\n');
for (s = i = 0; i < n; i++)
{
scanf("%d", a + i);
s += a[i];
}
s /= n;
for (t = i = 0; i < n; i++)
{
if (a[i] > s)
t += a[i] - s;
}
printf("%d\n", t);
}
return 0;
}
#include <stdio.h>
int A(int n)
{
int i = 1;
while (n)
{
if (n % 10 == 4 || n % 100 == 62)
return i;
n /= 10;
i *= 10;
}
return 0;
}
int main(void)
{
int n, m, i, c, b;
int *a = new int[1000000];
a[0] = 0;
for (c = 0,i = 1; i < 1000000; i += b)
{
b = A(i);
if (!b) c += b = 1;
for (n = 0; n < b; n++)
a[i + n] = c;
}
while (scanf("%d%d", &n, &m), n + m)
printf("%d\n", a[m] - a[n-1]);
return 0;
}
#include <stdio.h>
int main(void)
{
double sum = 0, d, n;
while (scanf("%*s") != EOF)
{
scanf("%lf%lf", &n, &d);
sum += n * d;
}
printf("%.1f\n", sum);
return 0;
}
#include <stdio.h>
int main(void)
{
char c;
int i = 0, n;
while ((c = getchar()) != '@')
{
scanf("%d%*c", &n);
printf(i ? "\n%*c\n" : "%*c\n", n, c);
if (n == 1)
{
i = 1;
continue;
}
for (i = 1; i + 1 < n; i++)
printf("%*c%*c\n", n - i, c, i * 2, c);
for (i = 0; i < 2 * n - 1; i++)
putchar(c);
putchar('\n');
}
return 0;
}
#include <math.h>
#include <stdio.h>
#define s(x) ((x)*(x))
int main(void)
{
int x, y;
while (scanf("%d%d", &x, &y), x+y)
puts(s(x)-4*y >= 0 && s(x)-4*y - s((int)sqrt(s(x)-4*y)) == 0 ? "Yes" : "No");
return 0;
}
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define MAX 1000
typedef struct
{
char name[11];
int sum;
int total;
} credit;
int cmp(const void *a, const void *b)
{
if ((*(credit *)a).total != (*(credit *)b).total)
return (*(credit *)a).total - (*(credit *)b).total;
else if ((*(credit *)b).sum != (*(credit *)a).sum)
return (*(credit *)b).sum - (*(credit *)a).sum;
else
return strcmp((*(credit *)b).name, (*(credit *)a).name);
}
int main(void)
{
int res, t, f;
int i, n, m, j;
char style[10];
credit c[MAX] = {0};
scanf("%d%d", &n, &m);
for (i = 0; scanf("%s", c[i].name) != EOF; i++)
{
for (j = 0; j < n; j++)
{
scanf("%s", style);
res = sscanf(style, "%d(%d)", &t, &f);
if (res == 2)
{
c[i].total++;
c[i].sum += t + f * m;
}
else if (res == 1 && t > 0)
{
c[i].total++;
c[i].sum += t;
}
}
}
qsort(c, i, sizeof(credit), cmp);
for (i--; i >= 0; i--)
printf("%-10s %2d %4d\n", c[i].name, c[i].total, c[i].sum);
return 0;
}
#include <set>
#include <map>
#include <string>
#include <iostream>
using namespace std;
int main(void)
{
int n, i, t;
string b, e;
set <string> s;
set <string>::iterator it;
map <string, string> m;
map <string, string>::iterator iter;
while (cin >> n, n)
{
s.clear();
m.clear();
for (i = 0; i < n; i++)
{
cin >> b >> e;
s.insert(b);
s.insert(e);
m[e] = b;
}
for (t = 0, it = s.begin(); it != s.end(); it++)
{
if (!m[*it].length())
t++;
}
puts(t == 1 ? "Yes" : "No");
}
return 0;
}
#include <set>
#include <map>
#include <cstdio>
using namespace std;
int main(void)
{
int n, i, t;
set <int> s;
set <int>::iterator it;
map <int, int> m;
map <int, int>::iterator iter;
while (scanf("%d", &n), n)
{
s.clear();
m.clear();
for (i = 0; i < n; i++)
{
scanf("%d", &t);
s.insert(t);
m[t]++;
}
for (it = s.begin(); it != s.end(); it++)
{
if (m[*it] == 1)
{
printf("%d\n", *it);
break;
}
}
}
return 0;
}
#include <stdio.h>
int main(void)
{
int n;
int a, b;
scanf("%d", &n);
while (n--)
{
scanf("%d%d", &a, &b);
printf("%d\n", (a % 100 + b % 100) % 100);
}
return 0;
}
#include <stdio.h>
int Sum(int n, int as)
{
int sum = 0;
while (n)
{
sum += n % as;
n /= as;
}
return sum;
}
int main(void)
{
int n;
while (scanf("%d", &n), n)
printf(Sum(n,10)==Sum(n,12)&&Sum(n,10)==Sum(n,16)?"%d is a Sky Number.\n":"%d is not a Sky Number.\n", n);
return 0;
}
#include <stdio.h>
int p[10001] = {0, 0, 1, 1, 0, 1};
int creat_prime(int prime[],int n,int total)
{
register int i;
register int j;
register int gab=2;
register int count;
for(i=7;i<=n;i+=gab)
{
count=1;
gab=6-gab;
for(j=0;prime[j]*prime[j]<=i;j++)
{
if(i%prime[j]==0)
{
count=0;
break;
}
}
if(count)
{
prime[total]=i;
p[i] = 1;
total++;
}
}
return total;
}
int main(void)
{
int prime[1229]={2,3,5};
int total=3;
int i;
int n=10001;
total=creat_prime(prime,n,total);
while (scanf("%d", &n), n)
{
total = 0;
if (p[n - 2] && n - 2 != 2) total++;
for (i = 3; i < n / 2; i++)
{
if (p[i] && p[n - i])
total++;
}
printf("%d\n", total);
}
}
#include <stdio.h>
int main(void)
{
int i;
int a, b;
int c;
while (scanf("%d%d", &a, &b), a + b)
{
for (c = i = 0; i < 100; i++)
{
if ((a * 100 + i) % b == 0)
printf(c++ ? " %02d" : "%02d", i);
}
putchar('\n');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment