FX is defeated and withered today. The market is not rebounding and the weekend is closed to Tokyo, which is the worst. This time it's not difficult, but I made a bug in the Eratosthenes sieve. It's hard to live.
Subtraction, no particular impression.
answerA.py
print(48-int(input()))
Check one character at a time. I made a character string from 0 to 9 and calculated whether it was in it, but it seems that it is OK even if it is "0" or more and "9" or less.
answerB.py
num=list("0123456789")
a,b=map(int,input().split())
s=input()
for i in range(a+b+1):
if i!=a:
if s[i] not in num:
print("No")
break
else:
if s[i]!="-":
print("No")
break
else:
print("Yes")
My head was too weak and I made many mistakes. Record what time you will arrive at each station in a variable called now. Then, for each station, consider the smallest multiple of f after s and after the time you arrived at that station, and if you proceed by c from there, you will proceed to the next station. Can be solved with. I couldn't do this because I was thinking too much about FX. How stupid!
answerC.py
import math
n=int(input())
csf=[list(map(int,input().split())) for i in range(n-1)]
for j in range(n-1):
now=0
for i in range(j,n-1):
if csf[i][1]>=now:
now=csf[i][1]+csf[i][0]
else:
now=csf[i][1]-((csf[i][1]-now)//csf[i][2])*csf[i][2]+csf[i][0]
print(now)
print(0)
Given the interval query, it's clear to consider the difference in cumulative sums. In other words, you should ask for "a number similar to 2017" first before calculating the query, ** Eratosthenes Sieve ** (Other Articles Introduced in 0b49891986e8bb31e148)), enumerate the prime numbers, check "Numbers similar to 2017", and consider the cumulative sum. However, the Eratosthenes sieve was buggy and I was going to check "2017-like numbers", but it took a long time just to check the prime numbers. I want to eliminate such ** careless mistakes **.
answerD.cc
#include<algorithm>//sort,Binary search,Such
#include<bitset>//Fixed length bit set
#include<cmath>//pow,log etc.
#include<complex>//Complex number
#include<deque>//Queue for double-ended access
#include<functional>//sort greater
#include<iomanip>//setprecision(Floating point output error)
#include<iostream>//Input / output
#include<map>//map(dictionary)
#include<numeric>//iota(Generation of integer sequence),gcd and lcm(c++17)
#include<queue>//queue
#include<set>//set
#include<stack>//stack
#include<string>//String
#include<unordered_map>//Map with iterator but not keeping order
#include<unordered_set>//Set with iterator but not keeping order
#include<utility>//pair
#include<vector>//Variable length array
using namespace std;
typedef long long ll;
//macro
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //I want to omit arguments such as sort
#define SIZE(x) ((ll)(x).size()) //size to size_Change from t to ll
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define MA 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
ll sieve_check[MA+1];//i-th corresponds to integer i(1~100000)
//Implement the Eratosthenes sieve
void es(){
FOR(i,2,MA)sieve_check[i]=1;
//1 is a prime number, here 0 is not a prime number
for(ll i=2;i<=1000;i++){
if(sieve_check[i]==1){
for(ll j=2;j<=ll(MA/i);j++){
sieve_check[j*i]=0;
}
}
}
}
signed main(){
es();
vector<ll> pre(MA+1);FOR(i,1,MA)pre[i]=(i%2==1&&sieve_check[i]&&sieve_check[(i+1)/2]);
REP(i,MA)pre[i+1]+=pre[i];
ll q;cin >> q;
vector< pair<ll,ll> > ans(q);REP(i,q) cin >> ans[i].F >> ans[i].S;
REP(i,q)cout << pre[ans[i].S]-pre[ans[i].F-1] << endl;
}
Recommended Posts