D-Decimal
题目·:Given a positive integer n, determine if 1n is an infinite decimal in decimal base. If the answer is yes, print “Yes” in a single line, or print “No” if the answer is no.
Input
The first line contains one positive integer T (1≤T≤100), denoting the number of test cases.
For each test case:
Input a single line containing a positive integer n (1≤n≤100).
Output
Output T lines each contains a string “Yes” or “No”, denoting the answer to corresponding test case.
- 签到题
- 输入一个正整数 ,判断 是不是无限小数。
- 把 的2、5因子除去,如果最终的结果为1则不是,反之则是。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t; cin >> t;
while(t--)
{
int n; cin >> n;
if(n % 2 == 0)
while(n % 2 == 0) {n /= 2;}
if(n % 5 == 0)
while(n % 5 == 0) {n /= 5;}
if(n == 1) cout << "No\n";
else cout << "Yes\n";
}
return 0;
}
E - MUV LUV EXTRA
题目:定义一个算式
给你一个无限循环小数的前几位,选择一种循环节的方案使得上式结果最大。其中 由输入给定, 表示循环节已经开始出现的部分长度, 表示循环节的长度
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mx = 1e7 + 10;
char s2[mx], s1[mx];
int nextt[mx];
ll a, b;
void getNext(int len)
{
//nextt数组代表当前字符之前的字符串前缀后缀最长公共元素长度(KMP)
int i = 0, j = -1;
nextt[0] = -1;
while(i < len)
{
if(j == -1 || s2[i] == s2[j])
{
i++; j++;
nextt[i] = j;
}
else
j = nextt[j];
}
}
int main()
{
while(scanf("%d%d%s",&a,&b,s1) != EOF)
{
int len = 0;
//得到小数点后的数字串
for(int i = strlen(s1)-1; i >= 0; --i)
{
if(s1[i] == '.')
break;
s2[len++] = s1[i];
}
//得到nextt数组
getNext(len);
ll ans = a - b; //预设ans
for(int i = 1; i <= len; ++i)
ans = max(ans, a*i-b*(i-nextt[i])); //i-nextt[i]得到的就是最小循环节长度
printf("%lld\n",ans);
}
return 0;
}