#include<stdio.h>
int n;
long long m, md, wd, line;
int main()
{
int i;
long long a, b, c, gcd, k;
scanf("%d",&n);
for(i=1 ; i<=n ; i++)
{
scanf("%lld %lld %lld",&m,&md,&wd);
a=md%wd;
b=wd;
c=a%b;
while(c!=0)
{
a=b;
b=c;
c=a%b;
}
gcd=b;
k=wd/gcd;
line=(m*md)/wd;
line+=(m/k)*(k-1);
line+=(m%k);
printf("Case #%d: %lld\n",i,line);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1088 KB |
Output is correct |