結果
| 問題 |
No.2280 FizzBuzz Difference
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-22 02:31:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 2,000 ms |
| コード長 | 2,064 bytes |
| コンパイル時間 | 866 ms |
| コンパイル使用メモリ | 86,912 KB |
| 最終ジャッジ日時 | 2025-02-12 12:50:27 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:44:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
44 | int tc; scanf("%d", &tc); while(tc) { tc--;
| ~~~~~^~~~~~~~~~~
main.cpp:45:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | scanf("%lld %lld %lld %lld", &m, &a, &b, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;
bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
class mypcmp {
public:
bool operator()(const int& a, const int& b) {
return a<b;
}
};
long long egcd(long long a, long long b, long long *x, long long *y)
{
if (a == 0) {
*x = 0; *y = 1;
return b;
}
long long _x, _y;
long long g = egcd(b % a, a, &_x, &_y);
*x = _y - (b/a) * _x;
*y = _x;
return g;
}
int main() {
int n, i;
LL m, a, b, k, x, y, g, v, c, r, t, fa, fb, cx;
int tc; scanf("%d", &tc); while(tc) { tc--;
scanf("%lld %lld %lld %lld", &m, &a, &b, &k);
g = egcd(a, b, &x, &y);
v=a/g; v*=b;
if (k>a) printf("0\n");
else if (k==a) {
m -= m%a;
r = m/a-m/b-1+m/v;
printf("%lld\n", r);
} else {
if (k%g) printf("0\n");
else {
y=-y;
// x*a-y*b = g
x*=(k/g); y*=(k/g);
// x*a-y*b = k
fa=b/g; fb=a/g;
cx=x/fa;
x-=cx*fa;
y-=cx*fb;
while (x<=0) { x+=fa; y+=fb; }
while (y<=0) { x+=fa; y+=fb; }
r=m/a-x;
if (r<0) r=0;
else {
r = r/fa+1;
}
// printf("%lld*%lld-%lld*%lld=%lld --> %lld\n", x, a, y, b, k, r);
x=-x; y=-y;
while (x<=0) { x+=fa; y+=fb; }
while (y<=0) { x+=fa; y+=fb; }
t = m/b-y;
if (t<0) t=0;
else t = t/fb+1;
// printf("%lld*%lld-%lld*%lld=-%lld --> %lld\n", x, a, y, b, k, t);
r+=t;
printf("%lld\n", r);
}
}
}
return 0;
}