Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relatively prime if there are no integers x > 1, y > 0, z > 0 such that a = xy and b = xz.
There are several test cases. For each test case, standard input contains a line with n <= 1,000,000,000. A line containing 0 follows the last case.
For each test case there should be single line of output answering the question posed above.
7 120
6 4
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; int a[1000010]; int main() { int t; int num=0,sum=0,max=0; cin >> t; while(t--) { int n,j=0; cin >> n; for(int i=0;i<n;i++) { cin >> a[i] ; if(max<a[i]) max=a[i]; } for(j;j<n;j++) { if(a[j]!=max) sum+=a[j]; if(sum>=max-1) break; } if(j==n) cout << "No" <<endl; else cout << "Yes" <<endl; } return 0; }
本文探讨了如何计算小于给定正整数n的所有与n互质的正整数的数量。互质定义为两个整数a和b不存在大于1的整数x使得a和b都能被x整除。文章通过示例输入输出展示了程序处理此类问题的方法。
7397

被折叠的 条评论
为什么被折叠?



