A | B | C | D | E | F |
---|---|---|---|---|---|
√ | √ | √ | √ |
https://atcoder.jp/contests/aising2020
How many multiples of d are there among the integers between L and R (inclusive)?
#include
using namespace std;
typedef long long LL;
int main(){
int l, r, d;
cin>>l>>r>>d;
int cnt = 0;
for(int i = l; i <= r; i++) if(i % d == 0) cnt++;
cout<
输出下标、值均为奇数的数的个数。题目中Square不是平方相关…
#include
using namespace std;
typedef long long LL;
int main(){
int n;
cin>>n;
int a[200];
int cnt = 0;
for(int i = 0; i < n; i++)cin>>a[i];
for(int i = 0; i < n; i++) if(a[i] & 1 && (i + 1) & 1) cnt++;
cout<
Let f(n)f(n) be the number of triples of integers (x,y,z)(x,y,z) that satisfy both of the following conditions:
Given an integer N, find each of f(1),f(2),f(3),…,f(N). 1≤N≤104
求符合条件的(x,y,z)个数
需要注意到在n的限制下100是x,y,z的上界,直接对xyz遍历。
#include
using namespace std;
typedef long long LL;
int main(){
int n;
cin>>n;
int ans[20000] = {};
for(int i = 1; i <= 100; i++){
for (int j = 1; j <= 100; ++j) {
for (int k = 1; k <= 100; ++k) {
if(i * i + j * j + k * k + i * j + i * k + j *k < 10004)
ans[i * i + j * j + k * k + i * j + i * k + j *k] ++;
}
}
}
for (int l = 0; l < n; ++l) {
cout<
f ( X 1 ) , f ( X 2 ) , … , f ( X N ) , 1 ≤ N ≤ 2 × 1 0 5 f(X_1), f(X_2), \ldots, f(X_N) , 1 \leq N \leq 2 \times 10^5 f(X1),f(X2),…,f(XN),1≤N≤2×105
#include
using namespace std;
typedef long long LL;
int ff[200005] = {};
int f(int x) {
if (x == 0)return 0;
if (ff[x]) return ff[x];
int cnt1 = 0;
for (int i = 0; i < 20; i++) {
if (x & (1 << i))cnt1++;
}
int i1 = x % cnt1;
if (i1 == 0) {
ff[x] = 1;
return 1;
}
return ff[x] = f(i1) + 1;
}
int mmd[200005];
string s;
int ans[200006];
int main() {
int n;
cin >> n;
int p = 0;
cin >> s;
int cnt1 = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '1') cnt1++;
}
int mmd[3] = {};
int d = 1;
if(cnt1 >= 2) {
for (int i = 0; i < n; ++i) {
if(s[n - i - 1] == '1'){
mmd[0] += d;
mmd[0] %= cnt1 - 1;
}
d *= 2;
d %= cnt1 - 1;
}
}
d = 1;
if(cnt1 >= 1){
for (int i = 0; i < n; ++i) {
if(s[n - i - 1] == '1'){
mmd[1] += d;
mmd[1] %= cnt1;
}
d *= 2;
d %= cnt1;
}
}
d = 1;
for (int i = 0; i < n; ++i) {
if(s[n - i - 1] == '1'){
mmd[2] += d;
mmd[2] %= cnt1 + 1;
}
d *= 2;
d %= cnt1 + 1;
}
int d1 = 1;
int d2 = 1;
for (int i = 0; i < n; ++i) {
bool add1 = s[n - i - 1] == '0';
int md = cnt1 + (add1 ? 1 : -1);
if(md)ans[n - i - 1] = f((mmd[add1 ? 2: 0] + (add1 ? d1 : -d2) + md) % md) + 1;
else ans[n - i - 1] = 0;
d1 *= 2;
d2 *= 2;
d1 %= cnt1 + 1;
if(cnt1 - 1 != 0) d2 %= cnt1 - 1;
}
for (int i = 0; i < n; ++i) {
cout<