#include <stdio.h> #include <stdlib.h> #include <string.h> // #include <math.h> not suitable for such large number. long long R(long long B, long long P, long long M){ long long result = 1; if(P == 0) return 1; else if(P == 1) return B % M; else{ result = result * R(B, P / 2, M); if(P % 2) return result * result * B % M; else return result * result % M; } } int main(){ long long B, P, M; while(scanf("%lld%lld%lld", &B, &P, &M) != EOF){ printf("%lld\n", R(B, P, M)); } return 0; } |
#include <stdio.h> int main(){ int n, k; int r; // r for result; while(scanf("%d %d", &n, &k) != EOF){ r = n; while(n / k){ r += n / k; n = n / k + n % k; } printf("%d\n", r); } return 0; } |
#include <stdio.h> #include <string.h> #define MAX_LEN 256 int main() { char s[MAX_LEN], t[MAX_LEN]; while (scanf("%s %s", s, t) != EOF) { int s_len = strlen(s), t_len = strlen(t); // set strlen int s_idx = 0, t_idx = 0; // refresh while (s_idx < s_len && t_idx < t_len) { if (s[s_idx] == t[t_idx]) s_idx++; t_idx++; } if (s_idx == s_len) printf("Yes\n"); else printf("No\n"); } return 0; } |
#include <stdio.h> int main(){ int w, h_c, n; // waves, height, numbers scanf("%d", &w); for(int CASE = 0; CASE < w; CASE++){ scanf("\n%d", &h_c); scanf("%d", &n); for(int i = 0; i < n; i++){ if(i == n - 1){ // if last wave int h = 1; while(h <= h_c){ for(int k = 0; k < h; k++){ printf("%d", h); } printf("\n"); h++; } h--; // same height while(h--){ for(int k = 0; k < h; k++){ printf("%d",h); } printf("\n"); } } else{ int h = 1; while(h <= h_c){ for(int k = 0; k < h; k++){ printf("%d", h); } printf("\n"); h++; } h--; // same height while(h--){ for(int k = 0; k < h; k++){ printf("%d",h); } printf("\n"); } printf("\n"); } } } return 0; } |