Submission #51398676
Source Code Expand
Copy
#include<bits/stdc++.h>using namespace std;#define int long long#define mid (l + r) / 2#define pb push_back#define mp make_pair#define pr pair<int, int>inline int read(){int x = 0, m = 1;char ch = getchar();while(!isdigit(ch)){if(ch == '-') m = -1;ch = getchar();}while(isdigit(ch)){x = x * 10 + ch - 48;ch = getchar();}
#include<bits/stdc++.h> using namespace std; #define int long long #define mid (l + r) / 2 #define pb push_back #define mp make_pair #define pr pair<int, int> inline int read(){ int x = 0, m = 1; char ch = getchar(); while(!isdigit(ch)){ if(ch == '-') m = -1; ch = getchar(); } while(isdigit(ch)){ x = x * 10 + ch - 48; ch = getchar(); } return x * m; } inline void write(int x){ if(x < 0){ putchar('-'); write(-x); return; } if(x >= 10) write(x / 10); putchar(x % 10 + '0'); } int sum(int l, int r) { return (r - l + 1) * (l + r) / 2; } int calc(int l, int r) { int s = 0; for (int i = l; i <= r; i++) s += i * i; return s; } signed main(){ int t = read(); while (t--) { int n = read(), ans = 0, m = sqrtl(n); for (int i = 1; i * i <= n; i *= 10) { if (i <= (n - i + 1) / i) ans += i; int l = max(1ll, i - 2), r = min(i - 1, (int)sqrtl(n + 1) - 1); if (l <= r) ans += calc(l + 1, r + 1) - i * sum(l, r); } write(ans); putchar('\n'); } }
Submission Info
Submission Time | |
---|---|
Task | D - Digit vs Square Root |
User | cyffffff |
Language | C++ 20 (gcc 12.2) |
Score | 0 |
Code Size | 1214 Byte |
Status | WA |
Exec Time | 16 ms |
Memory | 3668 KB |
Compile Error
Main.cpp: In function ‘int main()’: Main.cpp:51:34: warning: unused variable ‘m’ [-Wunused-variable] 51 | int n = read(), ans = 0, m = sqrtl(n); | ^
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 500 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt |
All | sample_01.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 1 ms | 3504 KB |
test_01.txt | AC | 1 ms | 3472 KB |
test_02.txt | WA | 5 ms | 3544 KB |
test_03.txt | WA | 15 ms | 3488 KB |
test_04.txt | WA | 8 ms | 3504 KB |
test_05.txt | AC | 16 ms | 3492 KB |
test_06.txt | WA | 9 ms | 3360 KB |
test_07.txt | WA | 10 ms | 3668 KB |