Skip to content

Instantly share code, notes, and snippets.

View magurofly's full-sized avatar
🐠
F

magurofly

🐠
F
View GitHub Profile
@magurofly
magurofly / b-sophie-germain.rb
Last active June 23, 2020 02:29
Check if the number is Sophie Germain prime, prime number, or not
#See also: ABC084 D - 2017-like Number
require "set"
n = gets.to_i
require "prime"
n_is_prime= false
n21_is_prime = false
@magurofly
magurofly / c.rb
Last active June 23, 2020 03:30
D - 2020に似た数
=begin
2020のように、ある文字列の2回以上の繰り返しとして表せる自然数を「2020に似た数」と呼ぶことにします。
Q個のクエリA_iとB_iが入力されたとき、A_iからB_iまでに2020に似た数が何個含まれるか求めなさい。
制約
1≦Q≦1e+5
1≦A_i≦B_i≦1e+5
入力
Q
@magurofly
magurofly / typical90_be.rb
Last active June 4, 2021 00:58
典型057
# 提出: https://atcoder.jp/contests/typical90/submissions/23159483
# 入力
N, M = gets.split.map(&:to_i)
A = Array.new(N) { gets; gets.split.map(&:to_i) }
S = gets.split.map(&:to_i)
# 行ベクトルの配列
xs = A.map { |indices|
x = 0
@magurofly
magurofly / typical90_061.js
Created June 9, 2021 05:30
典型061 スタック2本
function *main() {
const Q = +(yield);
const head = [], tail = [];
for (let i = 0; i < Q; i++) {
const [t, x] = (yield).split(" ").map(Number);
if (t == 1) {
head.push(x);
} else if (t == 2) {
tail.push(x);
} else if (t == 3) {
@magurofly
magurofly / rbst.rs
Created June 25, 2021 06:55
Randomized Binary Search Tree
fn main() {
let tree = RBST::new();
}
//https://tjkendev.github.io/procon-library/python/binary_search_tree/RBST.html
pub mod rbst {
use std::cmp::{Ordering::*, *};
pub struct RBST<K> {
root: Node<K>,
}
@magurofly
magurofly / atcoder-standings-watcher.user.js
Created July 5, 2021 07:47
AtCoder Standings Watcher
// ==UserScript==
// @name AtCoder Standings Watcher
// @namespace https://atcoder.jp/
// @version 0.2.7
// @description Watch standings and notifies
// @author magurofly
// @match https://atcoder.jp/contests/*
// @icon https://www.google.com/s2/favicons?domain=atcoder.jp
// @grant GM_notification
// @grant unsafeWindow
#![allow(non_snake_case, dead_code)]
#[fastout]
fn main() {
input! {
N: usize, mut W: Weight,
mut X: [(Value, Weight, Count); N],
}
let mut Y = vec![vec![]; 20];
N, K, M = gets.split.map(&:to_i)
sum = 0
(1 .. M - 1).each do |i|
count = (N - i) / M
sum += count * i.pow(K, M)
sum %= M
end
puts sum
@magurofly
magurofly / naive.rb
Last active August 12, 2021 16:02
愚直解 https%3A//twitter.com/realDivineJK/status/1425847790345748492
N, K, M = gets.split.map(&:to_i)
sum = 0
(1 .. N).each do |i|
sum += i.pow(K, M)
sum %= M
end
puts sum
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/segtree>
using namespace atcoder;
#define rep(i, l, r) for (auto i = (l); i < (r); i++)
#define all(a) a.begin(), a.end()
#define chmin(dest, src) if ((dest) > (src)) dest = (src)
#define chmax(dest, src) if ((dest) < (src)) dest = (src)
using ll = int;